Class: ActiveRecord::Associations::BelongsToAssociation
- Inherits:
-
SingularAssociation
- Object
- Association
- SingularAssociation
- ActiveRecord::Associations::BelongsToAssociation
- Defined in:
- lib/active_record/associations/belongs_to_association.rb
Overview
:nodoc:
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Association
#inversed, #owner, #reflection, #target
Instance Method Summary collapse
-
#decrement_counters ⇒ Object
:nodoc:.
- #default(&block) ⇒ Object
- #handle_dependency ⇒ Object
-
#increment_counters ⇒ Object
:nodoc:.
- #replace(record) ⇒ Object
- #reset ⇒ Object
- #updated? ⇒ Boolean
Methods inherited from SingularAssociation
#build, #force_reload_reader, #reader, #writer
Methods inherited from Association
#aliased_table_name, #association_scope, #create, #create!, #initialize, #initialize_attributes, #interpolate, #klass, #load_target, #loaded!, #loaded?, #marshal_dump, #marshal_load, #reload, #remove_inverse_instance, #reset_scope, #scope, #set_inverse_instance, #stale_target?, #target_scope
Constructor Details
This class inherits a constructor from ActiveRecord::Associations::Association
Instance Method Details
#decrement_counters ⇒ Object
:nodoc:
37 38 39 |
# File 'lib/active_record/associations/belongs_to_association.rb', line 37 def decrement_counters # :nodoc: update_counters(-1) end |
#default(&block) ⇒ Object
24 25 26 |
# File 'lib/active_record/associations/belongs_to_association.rb', line 24 def default(&block) writer(owner.instance_exec(&block)) if reader.nil? end |
#handle_dependency ⇒ Object
5 6 7 |
# File 'lib/active_record/associations/belongs_to_association.rb', line 5 def handle_dependency target.send([:dependent]) if load_target end |
#increment_counters ⇒ Object
:nodoc:
41 42 43 |
# File 'lib/active_record/associations/belongs_to_association.rb', line 41 def increment_counters # :nodoc: update_counters(1) end |
#replace(record) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/active_record/associations/belongs_to_association.rb', line 9 def replace(record) if record raise_on_type_mismatch!(record) update_counters_on_replace(record) replace_keys(record) set_inverse_instance(record) @updated = true else decrement_counters remove_keys end self.target = record end |
#reset ⇒ Object
28 29 30 31 |
# File 'lib/active_record/associations/belongs_to_association.rb', line 28 def reset super @updated = false end |
#updated? ⇒ Boolean
33 34 35 |
# File 'lib/active_record/associations/belongs_to_association.rb', line 33 def updated? @updated end |