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



33
34
35
36
37
38
39
# File 'lib/cequel/record/belongs_to_association.rb', line 33

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

  @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)



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

def_delegator :association_class, :key_columns, :association_key_columns

#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



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_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



54
55
56
# File 'lib/cequel/record/belongs_to_association.rb', line 54

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