Class: Cequel::Record::BelongsToAssociation
- Inherits:
-
Object
- Object
- Cequel::Record::BelongsToAssociation
- Extended by:
- Util::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.
-
#foreign_keys ⇒ Array
readonly
Array of foreign key symbols.
-
#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.
Methods included from Util::Forwardable
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.
35 36 37 38 39 40 41 42 |
# File 'lib/cequel/record/belongs_to_association.rb', line 35 def initialize(owner_class, name, = {}) .assert_valid_keys(:class_name, :foreign_key) @foreign_keys = Array(.fetch(:foreign_key, [])).map { |x| x.to_sym } @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.
25 |
# File 'lib/cequel/record/belongs_to_association.rb', line 25 def_delegator :association_class, :key_columns, :association_key_columns |
#foreign_keys ⇒ Array (readonly)
Returns array of foreign key symbols.
21 22 23 |
# File 'lib/cequel/record/belongs_to_association.rb', line 21 def foreign_keys @foreign_keys end |
#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`.
47 48 49 |
# File 'lib/cequel/record/belongs_to_association.rb', line 47 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.
57 58 59 |
# File 'lib/cequel/record/belongs_to_association.rb', line 57 def instance_variable_name @instance_variable_name ||= :"@#{name}" end |