11175
(-- --)
March 15, 2008, 2:06pm
1
Tim Booher wrote:
User -> Order -> Registration <- Camp
So a user has many orders, orders have many registrations and camps have
many registrations.
I have all the associations written up correctly, but I want to know how
to get all the users for a particular camp.
class Camp < ActiveRecord::Base
has_many :registrations
has_many :orders, :through => :registrations, :uniq => true, :include
=> :user
:
@camp = Camp.find_by_name("band camp")
mycampers = @camp.orders.map {|o| o.user}.uniq
11175
(-- --)
March 15, 2008, 3:27pm
2
Mark Bush wrote:
Tim Booher wrote:
User -> Order -> Registration <- Camp
So a user has many orders, orders have many registrations and camps have
many registrations.
I have all the associations written up correctly, but I want to know how
to get all the users for a particular camp.
class Camp < ActiveRecord::Base
has_many :registrations
has_many :orders, :through => :registrations, :uniq => true, :include
=> :user
:
@camp = Camp.find_by_name("band camp")
mycampers = @camp.orders.map {|o| o.user}.uniq
this is great! thanks for your help. is :uniq a custom method of
has_many :through ?
best,
tim
11175
(-- --)
March 15, 2008, 5:12pm
3
Tim Booher wrote:
this is great! thanks for your help. is :uniq a custom method of
has_many :through ?
You can use ":uniq => true" for any "has_many" (and HABTM) association,
however it is most useful for ":through" types since direct associations
that need to be unique collections can be handled in the model
validation to prevent duplicates in the first place.