Class: NinjaModel::Associations::BelongsToAssociation
- Inherits:
-
AssociationProxy
- Object
- AssociationProxy
- NinjaModel::Associations::BelongsToAssociation
- Defined in:
- lib/ninja_model/associations/belongs_to_association.rb
Instance Method Summary collapse
-
#initialize(owner, reflection) ⇒ BelongsToAssociation
constructor
A new instance of BelongsToAssociation.
- #replace(record) ⇒ Object
Methods inherited from AssociationProxy
#===, #inspect, #loaded, #loaded?, #proxy_owner, #proxy_reflection, #proxy_respond_to?, #proxy_target, #reload, #reset, #respond_to?, #send, #target, #target=
Constructor Details
#initialize(owner, reflection) ⇒ BelongsToAssociation
Returns a new instance of BelongsToAssociation.
4 5 6 |
# File 'lib/ninja_model/associations/belongs_to_association.rb', line 4 def initialize(owner, reflection) @owner, @reflection = owner, reflection end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class NinjaModel::Associations::AssociationProxy
Instance Method Details
#replace(record) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/ninja_model/associations/belongs_to_association.rb', line 8 def replace(record) if record.nil? @target = @owner[@reflection.primary_key_name] = nil else @target = (AssociationProxy === record ? record.target : record) @owner[@reflection.primary_key_name] = record_id(record) if record.persisted? @updated = true end loaded record end |