Class: Cequel::Record::BelongsToAssociation

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

Instance Method Summary collapse

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.

Parameters:

  • owner_class (Class)

    child class that declared ‘belongs_to`

  • name (Symbol)

    name of the association

  • options (Options) (defaults to: {})

    options for association

Options Hash (options):

  • :class_name (String)

    name of parent class

Since:

  • 1.0.0



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

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.

Returns:

  • (String)

    name of parent class

Since:

  • 1.0.0



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

def association_class_name
  @association_class_name
end

#association_key_columnsArray<Schema::Column> (readonly)

Returns key columns on the parent class.

Returns:



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

def_delegator :association_class, :key_columns, :association_key_columns

#nameSymbol (readonly)

Returns name of the association.

Returns:

  • (Symbol)

    name of the association

Since:

  • 1.0.0



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

def name
  @name
end

#owner_classClass (readonly)

Returns child class that declared ‘belongs_to`.

Returns:

  • (Class)

    child class that declared ‘belongs_to`

Since:

  • 1.0.0



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

def owner_class
  @owner_class
end

Instance Method Details

#association_classClass

Returns parent class declared by ‘belongs_to`.

Returns:

  • (Class)

    parent class declared by ‘belongs_to`

Since:

  • 1.0.0



43
44
45
# File 'lib/cequel/record/belongs_to_association.rb', line 43

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.

Returns:

  • (Symbol)

    instance variable name to use for storing the parent instance in a record

Since:

  • 1.0.0



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

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