Class: JsonApi::Resources::ToOneRelationship

Inherits:
Relationship show all
Defined in:
lib/json_api_ruby/resources/relationships.rb

Overview

convenience classes

Instance Attribute Summary

Attributes inherited from Relationship

#included, #name, #parent, #parent_model, #resources

Instance Method Summary collapse

Methods inherited from Relationship

#included?, #initialize, #links, #to_hash

Constructor Details

This class inherits a constructor from JsonApi::Resources::Relationship

Instance Method Details

#build_resources(options) ⇒ Object



86
87
88
89
90
91
92
93
# File 'lib/json_api_ruby/resources/relationships.rb', line 86

def build_resources(options)
  return unless included?
  resource_model = parent_model.send(name)
  return if resource_model.blank?

  resource_class = Discovery.resource_for_name(resource_model, options.merge(parent_resource: parent))
  @resources << resource_class.new(resource_model)
end

#data(options = {}) ⇒ Object



81
82
83
84
# File 'lib/json_api_ruby/resources/relationships.rb', line 81

def data(options={})
  identifier_hash = resource_object.identifier_hash if resource_object
  {'data' => identifier_hash}
end

#resource_objectObject



95
96
97
# File 'lib/json_api_ruby/resources/relationships.rb', line 95

def resource_object
  @resources.first
end