Class: JsonApi::Resources::ToManyRelationship
- Inherits:
-
Relationship
- Object
- Relationship
- JsonApi::Resources::ToManyRelationship
- Defined in:
- lib/json_api_ruby/resources/relationships.rb
Instance Attribute Summary
Attributes inherited from Relationship
#explicit_resource_class, #included, #name, #parent, #parent_model, #resources
Instance Method Summary collapse
-
#build_resources(options) ⇒ Object
Build the related resources.
- #data(options = {}) ⇒ Object
- #resource_objects ⇒ Object
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
Build the related resources
117 118 119 120 121 122 123 124 |
# File 'lib/json_api_ruby/resources/relationships.rb', line 117 def build_resources() return unless included? parent_model.send(name).each do |resource_model| resource_class = Discovery.resource_for_name(resource_model, .merge(parent_resource: parent, resource_class: explicit_resource_class)) @resources << resource_class.new(resource_model) end end |
#data(options = {}) ⇒ Object
109 110 111 112 113 114 |
# File 'lib/json_api_ruby/resources/relationships.rb', line 109 def data(={}) data = resource_objects.map do |object| object.identifier_hash end {'data' => data} end |
#resource_objects ⇒ Object
126 127 128 |
# File 'lib/json_api_ruby/resources/relationships.rb', line 126 def resource_objects @resources end |