Class: Cequel::Record::BelongsToAssociation
- Inherits:
-
Object
- Object
- Cequel::Record::BelongsToAssociation
- Extended by:
- Forwardable
- Defined in:
- lib/cequel/record/belongs_to_association.rb
Overview
Represents a parent association declared by belongs_to
Instance Attribute Summary collapse
-
#association_class_name ⇒ String
readonly
Name of parent class.
-
#association_key_columns ⇒ Array<Schema::Column>
readonly
Key columns on the parent class.
-
#name ⇒ Symbol
readonly
Name of the association.
-
#owner_class ⇒ Class
readonly
Child class that declared ‘belongs_to`.
Instance Method Summary collapse
-
#association_class ⇒ Class
Parent class declared by ‘belongs_to`.
-
#initialize(owner_class, name, options = {}) ⇒ BelongsToAssociation
constructor
private
A new instance of BelongsToAssociation.
-
#instance_variable_name ⇒ Symbol
private
Instance variable name to use for storing the parent instance in a record.
Constructor Details
#initialize(owner_class, name, options = {}) ⇒ BelongsToAssociation
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 BelongsToAssociation.
33 34 35 36 37 38 39 |
# File 'lib/cequel/record/belongs_to_association.rb', line 33 def initialize(owner_class, name, = {}) .assert_valid_keys(:class_name) @owner_class, @name = owner_class, name.to_sym @association_class_name = .fetch(:class_name, @name.to_s.classify) end |
Instance Attribute Details
#association_class_name ⇒ String (readonly)
Returns name of parent class.
19 20 21 |
# File 'lib/cequel/record/belongs_to_association.rb', line 19 def association_class_name @association_class_name end |
#association_key_columns ⇒ Array<Schema::Column> (readonly)
Returns key columns on the parent class.
23 |
# File 'lib/cequel/record/belongs_to_association.rb', line 23 def_delegator :association_class, :key_columns, :association_key_columns |
#name ⇒ Symbol (readonly)
Returns name of the association.
17 18 19 |
# File 'lib/cequel/record/belongs_to_association.rb', line 17 def name @name end |
#owner_class ⇒ Class (readonly)
Returns child class that declared ‘belongs_to`.
15 16 17 |
# File 'lib/cequel/record/belongs_to_association.rb', line 15 def owner_class @owner_class end |
Instance Method Details
#association_class ⇒ Class
Returns parent class declared by ‘belongs_to`.
44 45 46 |
# File 'lib/cequel/record/belongs_to_association.rb', line 44 def association_class @association_class ||= association_class_name.constantize end |
#instance_variable_name ⇒ Symbol
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 instance variable name to use for storing the parent instance in a record.
54 55 56 |
# File 'lib/cequel/record/belongs_to_association.rb', line 54 def instance_variable_name @instance_variable_name ||= :"@#{name}" end |