Method: RPCMapper::Association::Has#scope
- Defined in:
- lib/rpc_mapper/association.rb
#scope(object) ⇒ Object
Returns a scope on the target containing this association
Builds conditions on top of the base_scope generated from any finder options set with the association
has_many :widgets, :class_name => "Widget", :foreign_key => :widget_id
has_many :comments, :as => :parent
In addition to any finder options included with the association options the following will be added:
where( => source[:id])
Or for the polymorphic :comments association:
where(:parent_id => source[:id], :parent_type => source.class)
194 195 196 197 198 199 200 201 202 |
# File 'lib/rpc_mapper/association.rb', line 194 def scope(object) return nil unless object[self.primary_key] s = base_scope(object).where(self.foreign_key => object[self.primary_key]) if polymorphic? s = s.where( polymorphic_type => RPCMapper::Base.base_class_name(object.class) ) end s end |