Class: DuckRecord::Associations::BelongsToAssociation
- Inherits:
-
SingularAssociation
- Object
- Association
- SingularAssociation
- DuckRecord::Associations::BelongsToAssociation
- Defined in:
- lib/duck_record/associations/belongs_to_association.rb
Overview
:nodoc:
Instance Attribute Summary
Attributes inherited from Association
Instance Method Summary collapse
Methods inherited from SingularAssociation
#build, #force_reload_reader, #reader, #writer
Methods inherited from Association
#aliased_table_name, #association_scope, #create, #create!, #extensions, #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 DuckRecord::Associations::Association
Instance Method Details
#default(&block) ⇒ Object
21 22 23 |
# File 'lib/duck_record/associations/belongs_to_association.rb', line 21 def default(&block) writer(owner.instance_exec(&block)) if reader.nil? end |
#replace(record) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/duck_record/associations/belongs_to_association.rb', line 5 def replace(record) if owner.class.readonly_attributes.include?(reflection.foreign_key.to_s) return end if record raise_on_type_mismatch!(record) replace_keys(record) @updated = true else remove_keys end self.target = record end |
#reset ⇒ Object
25 26 27 28 |
# File 'lib/duck_record/associations/belongs_to_association.rb', line 25 def reset super @updated = false end |
#updated? ⇒ Boolean
30 31 32 |
# File 'lib/duck_record/associations/belongs_to_association.rb', line 30 def updated? @updated end |