Class: JSONAPI::Association::HasOne

Inherits:
JSONAPI::Association show all
Defined in:
lib/jsonapi/association.rb

Instance Attribute Summary

Attributes inherited from JSONAPI::Association

#acts_as_set, #class_name, #foreign_key, #name, #options, #type

Instance Method Summary collapse

Methods inherited from JSONAPI::Association

#primary_key

Constructor Details

#initialize(name, options = {}) ⇒ HasOne

Returns a new instance of HasOne.



18
19
20
21
22
23
# File 'lib/jsonapi/association.rb', line 18

def initialize(name, options={})
  super
  @class_name = options.fetch(:class_name, name.to_s.capitalize)
  @type = class_name.underscore.pluralize.to_sym
  @foreign_key ||= @key.nil? ? "#{name}_id".to_sym : @key
end