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
- #polymorphic_type ⇒ Object
-
#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
128 129 130 |
# File 'lib/rpc_mapper/association.rb', line 128 def collection? false end |
#foreign_key ⇒ Object
132 133 134 |
# File 'lib/rpc_mapper/association.rb', line 132 def foreign_key super || "#{id}_id".to_sym end |
#polymorphic? ⇒ Boolean
136 137 138 |
# File 'lib/rpc_mapper/association.rb', line 136 def polymorphic? !![:polymorphic] end |
#polymorphic_type ⇒ Object
140 141 142 |
# File 'lib/rpc_mapper/association.rb', line 140 def polymorphic_type "#{id}_type".to_sym 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])
156 157 158 159 160 |
# File 'lib/rpc_mapper/association.rb', line 156 def scope(object) if object[self.foreign_key] base_scope(object).where(self.primary_key => object[self.foreign_key]) end end |
#type ⇒ Object
124 125 126 |
# File 'lib/rpc_mapper/association.rb', line 124 def type :belongs_to end |