Class: Cequel::Record::HasManyAssociation
- Inherits:
-
Object
- Object
- Cequel::Record::HasManyAssociation
- Defined in:
- lib/cequel/record/has_many_association.rb
Overview
Represents a child association declared by has_many.
Instance Attribute Summary collapse
-
#association_class_name ⇒ Symbol
readonly
Name of the child class that this association contains.
-
#dependent ⇒ Boolean
readonly
Behavior for propagating destruction from parent to children.
-
#name ⇒ Symbol
readonly
Name of this association.
-
#owner_class ⇒ Class
readonly
Record class that declares this association.
Instance Method Summary collapse
-
#association_class ⇒ Class
Class of child association.
-
#initialize(owner_class, name, options = {}) ⇒ HasManyAssociation
constructor
private
A new instance of HasManyAssociation.
- #instance_variable_name ⇒ Object
Constructor Details
#initialize(owner_class, name, options = {}) ⇒ HasManyAssociation
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of HasManyAssociation.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/cequel/record/has_many_association.rb', line 31 def initialize(owner_class, name, = {}) .assert_valid_keys(:class_name, :dependent) @owner_class, @name = owner_class, name @association_class_name = .fetch(:class_name, name.to_s.classify) case [:dependent] when :destroy, :delete, nil @dependent = [:dependent] else fail ArgumentError, "Invalid :dependent option #{[:dependent].inspect}. " \ "Valid values are :destroy, :delete" end end |
Instance Attribute Details
#association_class_name ⇒ Symbol (readonly)
Returns name of the child class that this association contains.
17 18 19 |
# File 'lib/cequel/record/has_many_association.rb', line 17 def association_class_name @association_class_name end |
#dependent ⇒ Boolean (readonly)
Returns behavior for propagating destruction from parent to children.
20 21 22 |
# File 'lib/cequel/record/has_many_association.rb', line 20 def dependent @dependent end |
#name ⇒ Symbol (readonly)
Returns name of this association.
15 16 17 |
# File 'lib/cequel/record/has_many_association.rb', line 15 def name @name end |
#owner_class ⇒ Class (readonly)
Returns Record class that declares this association.
13 14 15 |
# File 'lib/cequel/record/has_many_association.rb', line 13 def owner_class @owner_class end |
Instance Method Details
#association_class ⇒ Class
Returns class of child association.
50 51 52 |
# File 'lib/cequel/record/has_many_association.rb', line 50 def association_class @association_class ||= association_class_name.constantize end |
#instance_variable_name ⇒ Object
55 56 57 |
# File 'lib/cequel/record/has_many_association.rb', line 55 def instance_variable_name @instance_variable_name ||= :"@#{name}" end |