inheriting scope from a has_many relationship
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!
I think what I was looking for was delegate
delegate :users, :to => :master_group
hope this helps someone...
精彩评论