Class: JSONAPI::Relationship::ToOne

Inherits:
JSONAPI::Relationship show all
Defined in:
lib/jsonapi/relationship.rb

Instance Attribute Summary collapse

Attributes inherited from JSONAPI::Relationship

#acts_as_set, #always_include_linkage_data, #class_name, #foreign_key, #name, #options, #parent_resource, #polymorphic

Instance Method Summary collapse

Methods inherited from JSONAPI::Relationship

#primary_key, #relation_name, #resource_klass, #table_name, #type, #type_for_source

Constructor Details

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

Returns a new instance of ToOne.


65
66
67
68
69
70
# File 'lib/jsonapi/relationship.rb', line 65

def initialize(name, options = {})
  super
  @class_name = options.fetch(:class_name, name.to_s.camelize)
  @foreign_key ||= "#{name}_id".to_sym
  @foreign_key_on = options.fetch(:foreign_key_on, :self)
end

Instance Attribute Details

#foreign_key_onObject (readonly)

Returns the value of attribute foreign_key_on


63
64
65
# File 'lib/jsonapi/relationship.rb', line 63

def foreign_key_on
  @foreign_key_on
end

Instance Method Details

#belongs_to?Boolean

Returns:

  • (Boolean)

72
73
74
# File 'lib/jsonapi/relationship.rb', line 72

def belongs_to?
  foreign_key_on == :self
end

#polymorphic_typeObject


76
77
78
# File 'lib/jsonapi/relationship.rb', line 76

def polymorphic_type
  "#{name}_type" if polymorphic?
end