Class: DatastaxRails::Associations::BelongsToAssociation
- Inherits:
-
SingularAssociation
- Object
- Association
- SingularAssociation
- DatastaxRails::Associations::BelongsToAssociation
- Defined in:
- lib/datastax_rails/associations/belongs_to_association.rb
Overview
belongs_to associations are the child side of a parent/child relationship
class Car < DatastaxRails::Base
uuid :id
uuid :owner_id
belongs_to :owner, class_name: 'Person'
end
Valid options:
-
class_name - The class on the other side (if different than what
classify
returns) -
foreign_key - The name of the foreign_key column if not just _id at the end of the association name
Instance Attribute Summary collapse
-
#updated ⇒ Object
(also: #updated?)
readonly
Returns the value of attribute updated.
Attributes inherited from Association
#loaded, #owner, #reflection, #target
Instance Method Summary collapse
Methods inherited from SingularAssociation
#build, #create, #create!, #reader, #writer
Methods inherited from Association
#aliased_column_family, #association_scope, #initialize, #klass, #load_target, #loaded!, #reload, #reset, #reset_scope, #scoped, #set_inverse_instance, #stale_target?, #target_scope
Constructor Details
This class inherits a constructor from DatastaxRails::Associations::Association
Instance Attribute Details
#updated ⇒ Object (readonly) Also known as: updated?
Returns the value of attribute updated.
15 16 17 |
# File 'lib/datastax_rails/associations/belongs_to_association.rb', line 15 def updated @updated end |
Instance Method Details
#replace(record) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/datastax_rails/associations/belongs_to_association.rb', line 17 def replace(record) raise_on_type_mismatch(record) if record replace_keys(record) set_inverse_instance(record) @updated = true if record self.target = record end |