Hello everyone, new to the community. I've done some research in the docs and various repos under jsonapi-rb organization, but I can't find an example of accepts_nested_attributes_for usage with a 'bulk' document. I think the JSONAPI spec may consider support for bulk updates/creates an extension, and it may have even been scrapped. I can see various PR's throughout the repos trying to implement this, but none which have been merged.
Has anyone else deserialized nested attributes from JSON-API format to a hash that rails can digest? Currently we have pretty standard rails controllers that accept form data from traditional ERB views/ form_for objects (cocoon actually) i.e.:
def update
if parent.update_attributes(update_params)
redirect_to next_url
else
render :edit
end
end
def update_params
params.require(:parent).permit(:parent_attr_1, children_attributes: [:id, :description, :first_name, :_destroy])
end
And we seek to convert them to accepting JSON-API formatted json. Something like this:
# in controller
deserializable_resource :children, class: DeserializableChild, only: [:update]
# in deserializer
class DeserializableChild < JSONAPI::Deserializable::Resource
key_format(&:underscore)
attributes
end
So my question is, is there a strategy I should follow? Has anyone done this in the past? Or is there another library that supports this out of the box? Our entire app is these nested forms, so it would be worth switching to AMS if they do support this officially. Thanks in advance for your insights!
class SerializableResource < JSONAPI::Serializable::Resource
extend JSONAPI::Serializable::Resource::KeyFormat
key_format -> (key) { key.to_s.camelize(:lower) }
end
include=comments
to the request.
"type": "database_users"
would resolve to DatabaseUser
and database_user_ids
. so something is going on there
=> <ActionController::Parameters {"_jsonapi"=><ActionController::Parameters {"data"=>{"relationships"=>{"database_users"=>{"data"=>[{"type"=>"database_users", "id"=>"1"}]}}, "type"=>"databases", "id"=>2}} permitted: false>, "format"=>:json, "controller"=>"databases", "action"=>"update", "id"=>"2", "database"=>{"type"=>"databases", "id"=>2, "database_user_ids"=>["1"], "database_user_types"=>["DatabaseUser"]}} permitted: false>
:to_ary
instead of :to_a
?
:to_a
but does not implement :to_ary
class: { Instance: SerializableInstance }
parameter, it doesn't render anything from the serializer, too