search for: role_type_id

Displaying 1 result from an estimated 1 matches for "role_type_id".

2009 May 12
4
has_many :through and scopes: how to mutate the set of associated objects?
...as_many :roles, :include => :role_type, :dependent => :destroy has_many :participants, :through => :roles, :source => :person do def as(role_name) self.scoped( :joins => ''CROSS JOIN role_types'', :conditions => [ "(roles.role_type_id = role_types.id) + " AND role_types.name = ?", role_name ] ) end end ... end Querying is easy: m = Movie.find_by_title(''Gran Milano'') m.participants.as(''director'') However, changing relations is painful. It...