Class: MagicModels::Associations::BelongsTo

Inherits:
Object
  • Object
show all
Defined in:
lib/magic_models/associations.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(foreign_key) ⇒ BelongsTo

Returns a new instance of BelongsTo.



6
7
8
9
10
# File 'lib/magic_models/associations.rb', line 6

def initialize(foreign_key)
  @table_name = foreign_key.to_table
  @primary_key = foreign_key.options[:primary_key]
  @foreign_key = foreign_key.options[:column]
end

Instance Attribute Details

#foreign_keyObject (readonly)

Returns the value of attribute foreign_key.



4
5
6
# File 'lib/magic_models/associations.rb', line 4

def foreign_key
  @foreign_key
end

#primary_keyObject (readonly)

Returns the value of attribute primary_key.



4
5
6
# File 'lib/magic_models/associations.rb', line 4

def primary_key
  @primary_key
end

Instance Method Details

#class_nameObject



20
21
22
# File 'lib/magic_models/associations.rb', line 20

def class_name
  @table_name.singularize.camelize
end

#macroObject



16
17
18
# File 'lib/magic_models/associations.rb', line 16

def macro
  'belongs_to'
end

#nameObject



12
13
14
# File 'lib/magic_models/associations.rb', line 12

def name
  @foreign_key.sub(/_id$/, '').singularize
end