Class: JsonApi::Parameters::Handlers::DefaultHandlers::ToOneRelationHandler
- Inherits:
-
BaseHandler
- Object
- BaseHandler
- JsonApi::Parameters::Handlers::DefaultHandlers::ToOneRelationHandler
- Includes:
- ActiveSupport::Inflector
- Defined in:
- lib/jsonapi_parameters/default_handlers/to_one_relation_handler.rb
Instance Attribute Summary
Attributes inherited from BaseHandler
#included, #relationship_key, #relationship_value
Instance Method Summary collapse
Methods inherited from BaseHandler
call, #find_included_object, #initialize
Constructor Details
This class inherits a constructor from JsonApi::Parameters::Handlers::DefaultHandlers::BaseHandler
Instance Method Details
#handle ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/jsonapi_parameters/default_handlers/to_one_relation_handler.rb', line 10 def handle = relationship_value.dig(:id) = relationship_value.dig(:type) included_object = find_included_object( related_id: , related_type: ) || {} return ["#{singularize(relationship_key)}_id".to_sym, ] if included_object.empty? included_object = { **(included_object[:attributes] || {}), id: }.tap do |body| body[:relationships] = included_object[:relationships] if included_object.key?(:relationships) # Pass nested relationships end ["#{singularize(relationship_key)}_attributes".to_sym, included_object] end |