Class: DatastaxRails::Associations::SingularAssociation
- Inherits:
-
Association
- Object
- Association
- DatastaxRails::Associations::SingularAssociation
- Defined in:
- lib/datastax_rails/associations/singular_association.rb
Overview
Encapsulates the common functionality between belongs_to and has_one relationships
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Association
#loaded, #owner, #reflection, #target
Instance Method Summary collapse
- #build(attributes = {}, options = {}) {|record| ... } ⇒ Object
- #create(attributes = {}, options = {}, &block) ⇒ Object
- #create!(attributes = {}, options = {}, &block) ⇒ Object
-
#reader(force_reload = false) ⇒ Object
Implements the reader method, e.g.
-
#writer(record) ⇒ Object
Implements the writer method, e.g.
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 Method Details
#build(attributes = {}, options = {}) {|record| ... } ⇒ Object
24 25 26 27 28 29 |
# File 'lib/datastax_rails/associations/singular_association.rb', line 24 def build(attributes = {}, = {}) record = build_record(attributes, ) yield(record) if block_given? set_new_record(record) record end |
#create(attributes = {}, options = {}, &block) ⇒ Object
16 17 18 |
# File 'lib/datastax_rails/associations/singular_association.rb', line 16 def create(attributes = {}, = {}, &block) create_record(attributes, , &block) end |
#create!(attributes = {}, options = {}, &block) ⇒ Object
20 21 22 |
# File 'lib/datastax_rails/associations/singular_association.rb', line 20 def create!(attributes = {}, = {}, &block) create_record(attributes, , true, &block) end |
#reader(force_reload = false) ⇒ Object
Implements the reader method, e.g. foo.bar for Foo.has_one :bar
6 7 8 9 |
# File 'lib/datastax_rails/associations/singular_association.rb', line 6 def reader(force_reload = false) reload if force_reload || !loaded? || stale_target? target end |
#writer(record) ⇒ Object
Implements the writer method, e.g. foo.items= for Foo.has_many :items
12 13 14 |
# File 'lib/datastax_rails/associations/singular_association.rb', line 12 def writer(record) replace(record) end |