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