Class: Syncano::ActiveRecord::Association::BelongsTo

Inherits:
Base
  • Object
show all
Defined in:
lib/syncano/active_record/association/belongs_to.rb

Overview

Class for belongs to association

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#has_many?, #has_one?

Constructor Details

#initialize(source_model, name) ⇒ BelongsTo

Constructor for belongs_to association

Parameters:

  • source_model (Class)
  • name (Symbol)


13
14
15
16
# File 'lib/syncano/active_record/association/belongs_to.rb', line 13

def initialize(source_model, name)
  super
  self.foreign_key = associated_model.name.foreign_key
end

Instance Attribute Details

#associated_modelObject

Returns the value of attribute associated_model.



8
9
10
# File 'lib/syncano/active_record/association/belongs_to.rb', line 8

def associated_model
  @associated_model
end

#foreign_keyObject

Returns the value of attribute foreign_key.



8
9
10
# File 'lib/syncano/active_record/association/belongs_to.rb', line 8

def foreign_key
  @foreign_key
end

#source_modelObject

Returns the value of attribute source_model.



8
9
10
# File 'lib/syncano/active_record/association/belongs_to.rb', line 8

def source_model
  @source_model
end

Instance Method Details

#belongs_to?TrueClass

Checks if association is belongs_to type

Returns:

  • (TrueClass)


20
21
22
# File 'lib/syncano/active_record/association/belongs_to.rb', line 20

def belongs_to?
  true
end