Class: RPCMapper::Association::BelongsTo
- Defined in:
- lib/rpc_mapper/association.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #collection? ⇒ Boolean
- #foreign_key ⇒ Object
- #polymorphic? ⇒ Boolean
-
#scope(object) ⇒ Object
Returns a scope on the target containing this association.
- #type ⇒ Object
Methods inherited from Base
#eager_loadable?, #initialize, #primary_key, #target_klass
Constructor Details
This class inherits a constructor from RPCMapper::Association::Base
Instance Method Details
#collection? ⇒ Boolean
78 79 80 |
# File 'lib/rpc_mapper/association.rb', line 78 def collection? false end |
#foreign_key ⇒ Object
82 83 84 |
# File 'lib/rpc_mapper/association.rb', line 82 def foreign_key super || "#{id}_id".to_sym end |
#polymorphic? ⇒ Boolean
86 87 88 |
# File 'lib/rpc_mapper/association.rb', line 86 def polymorphic? !![:polymorphic] end |
#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
belongs_to :foo, :foreign_key => :foo_id
In addition to any finder options included with the association options the following scope will be added:
where(:id => source[:foo_id])
98 99 100 |
# File 'lib/rpc_mapper/association.rb', line 98 def scope(object) base_scope(object).where(self.primary_key => object[self.foreign_key]) if object[self.foreign_key] end |
#type ⇒ Object
74 75 76 |
# File 'lib/rpc_mapper/association.rb', line 74 def type :belongs_to end |