inheriting scope from a has_many relationship
Posted
by
hb922
on Stack Overflow
See other posts from Stack Overflow
or by hb922
Published on 2011-02-25T23:22:04Z
Indexed on
2011/02/25
23:25 UTC
Read the original article
Hit count: 195
I am using ruby on rails 3.1 and have 2 models, an event and a group. Each event has_many groups, but has to have at least one "master" group, where the column :is_master => true
Class Group < ActiveRecord::Base
has_many :users
belongs_to :event
scope :master, where (:is_master => true)
end
Class Event< ActiveRecord::Base
has_many :groups
def master_group
groups.master
end
end
I want to be able to default all properties of the master group to the event, so for example, event.users.count should be the same as event.master_group.users.count.
Is there any way to do something like this? Can I do a has_many :through => master_group? Am I approaching this the wrong way?
Thanks!
© Stack Overflow or respective owner