Class: JSONApi::RelationshipSerializer::ToOneSerializer

Inherits:
JSONApi::RelationshipSerializer show all
Defined in:
lib/json_api/relationship_serializer.rb

Instance Method Summary collapse

Methods inherited from JSONApi::RelationshipSerializer

#as_json

Instance Method Details

#data_for(object, options) ⇒ Object



84
85
86
87
88
89
# File 'lib/json_api/relationship_serializer.rb', line 84

def data_for(object, options)
  return if options[:data] == false

  id = relationship_for(object, options)
  resource_identifier_for(type_for(object, options), id)
end

#key_for(**options) ⇒ Object



80
81
82
# File 'lib/json_api/relationship_serializer.rb', line 80

def key_for(**options)
  "#{super}_id"
end


91
92
93
94
95
96
97
98
# File 'lib/json_api/relationship_serializer.rb', line 91

def links_for(object, options)
  return if options[:links] != true

  id   = Utils.canonicalize_id(object.send(options[:id_attribute] || :id))
  type = options[:name]

  { related: "#{options[:base_url] || ""}/#{options[:parent_type]}/#{id}/#{type}" }
end