OK, still learning here... here''s a rough sketch of my model...
User
has_and_belongs_to_many :customers
Customer
has_and_belongs_to_many :users
has_many :widgets
Widgets
belongs_to customer
Each user can be associated with one or more customers
Each customer has multiple users
Each widget is associated with a customer
I’ve seen tons of examples like this:
If I want to do something like this…
u = Users.find_by_name(''Jeff'')
#returns one user
puts u.customers
#returns multiple customer objects
my_widgets = u.customers.widgets
If I want to get a list of my widgets, this doesn’t work if I belong to
multiple customers, since u.customers returns an array of customer
objects that belong to the user
So, if I want to get a list of my widgets, do I have to do something
like this as a part of my user model, or is there an easier way to do
this?
def my_widgets
    @w=[]
    self.customers.each do |c|
      @w << c.widgets
    end
    return @w
end
Thanks in advance--
-Jeff Wigal
-- 
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---