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.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cequel/record/has_many_association.rb', line 30 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.
16 17 18 |
# File 'lib/cequel/record/has_many_association.rb', line 16 def association_class_name @association_class_name end |
#dependent ⇒ Boolean (readonly)
Returns behavior for propagating destruction from parent to children.
19 20 21 |
# File 'lib/cequel/record/has_many_association.rb', line 19 def dependent @dependent end |
#name ⇒ Symbol (readonly)
Returns name of this association.
14 15 16 |
# File 'lib/cequel/record/has_many_association.rb', line 14 def name @name end |
#owner_class ⇒ Class (readonly)
Returns Record class that declares this association.
12 13 14 |
# File 'lib/cequel/record/has_many_association.rb', line 12 def owner_class @owner_class end |
Instance Method Details
#association_class ⇒ Class
Returns class of child association.
49 50 51 |
# File 'lib/cequel/record/has_many_association.rb', line 49 def association_class @association_class ||= association_class_name.constantize end |
#instance_variable_name ⇒ Object
54 55 56 |
# File 'lib/cequel/record/has_many_association.rb', line 54 def instance_variable_name @instance_variable_name ||= :"@#{name}" end |