Class: MagicModels::Associations::BelongsTo
- Inherits:
-
Object
- Object
- MagicModels::Associations::BelongsTo
- Defined in:
- lib/magic_models/associations.rb
Instance Attribute Summary collapse
-
#foreign_key ⇒ Object
readonly
Returns the value of attribute foreign_key.
-
#primary_key ⇒ Object
readonly
Returns the value of attribute primary_key.
Instance Method Summary collapse
- #class_name ⇒ Object
-
#initialize(foreign_key) ⇒ BelongsTo
constructor
A new instance of BelongsTo.
- #macro ⇒ Object
- #name ⇒ Object
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.[:primary_key] @foreign_key = foreign_key.[:column] end |
Instance Attribute Details
#foreign_key ⇒ Object (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_key ⇒ Object (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_name ⇒ Object
20 21 22 |
# File 'lib/magic_models/associations.rb', line 20 def class_name @table_name.singularize.camelize end |
#macro ⇒ Object
16 17 18 |
# File 'lib/magic_models/associations.rb', line 16 def macro 'belongs_to' end |
#name ⇒ Object
12 13 14 |
# File 'lib/magic_models/associations.rb', line 12 def name @foreign_key.sub(/_id$/, '').singularize end |