Class: AttrJson::Associations::Association::BelongsTo

Inherits:
Base
  • Object
show all
Defined in:
lib/attr_json/associations/association/belongs_to.rb

Instance Attribute Summary

Attributes inherited from Base

#class_name, #foreign_key, #klass, #name, #options, #owner, #primary_key, #scope

Instance Method Summary collapse

Methods inherited from Base

#initialize, #scoped

Constructor Details

This class inherits a constructor from AttrJson::Associations::Association::Base

Instance Method Details

#resolve_foreign_keyObject



12
13
14
15
16
17
18
# File 'lib/attr_json/associations/association/belongs_to.rb', line 12

def resolve_foreign_key
  if @name.to_s == @name.to_s.pluralize
    "#{@name.to_s.singularize}_ids"
  else
    "#{@name}_id"
  end
end

#resolve_primary_keyObject



8
9
10
# File 'lib/attr_json/associations/association/belongs_to.rb', line 8

def resolve_primary_key
  @klass.primary_key.to_s
end