Class: Cequel::Record::BelongsToAssociation

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from Util::Forwardable

delegate

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.

Options Hash (options):

  • :class_name (String)

    name of parent class

Since:

  • 1.0.0



35
36
37
38
39
40
41
42
# File 'lib/cequel/record/belongs_to_association.rb', line 35

def initialize(owner_class, name, options = {})
  options.assert_valid_keys(:class_name, :foreign_key)

  @foreign_keys = Array(options.fetch(:foreign_key, [])).map { |x| x.to_sym }
  @owner_class, @name = owner_class, name.to_sym
  @association_class_name =
    options.fetch(:class_name, @name.to_s.classify)
end

Instance Attribute Details

#association_class_nameString (readonly)

Returns name of parent class.

Since:

  • 1.0.0



19
20
21
# File 'lib/cequel/record/belongs_to_association.rb', line 19

def association_class_name
  @association_class_name
end

#association_key_columnsArray<Schema::Column> (readonly)



25
# File 'lib/cequel/record/belongs_to_association.rb', line 25

def_delegator :association_class, :key_columns, :association_key_columns

#foreign_keysArray (readonly)

Returns array of foreign key symbols.

Since:

  • 1.0.0



21
22
23
# File 'lib/cequel/record/belongs_to_association.rb', line 21

def foreign_keys
  @foreign_keys
end

#nameSymbol (readonly)

Returns name of the association.

Since:

  • 1.0.0



17
18
19
# File 'lib/cequel/record/belongs_to_association.rb', line 17

def name
  @name
end

#owner_classClass (readonly)

Returns child class that declared ‘belongs_to`.

Since:

  • 1.0.0



15
16
17
# File 'lib/cequel/record/belongs_to_association.rb', line 15

def owner_class
  @owner_class
end

Instance Method Details

#association_classClass

Returns parent class declared by ‘belongs_to`.

Since:

  • 1.0.0



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_nameSymbol

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.

Since:

  • 1.0.0



57
58
59
# File 'lib/cequel/record/belongs_to_association.rb', line 57

def instance_variable_name
  @instance_variable_name ||= :"@#{name}"
end