-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Thank you for this library; it has saved us a lot of time.
If my reading of this previous issue is correct, it appears that initially this library started out with ignoring ids entirely, including those generated client-side, but support for ids was added for those who require it. However, I don't see an option to opt-out of this behaviour.
The spec permits ignoring client-generated IDs:
A server MAY accept a client-generated ID along with a request to create a resource.
and it would seem the transforming functionality that jsonapi_parameters provides, is a natural (and efficient) point to do that.
The particular issue we have is that we need POST and PATCH requests that support "nested attributes", which as part of the client serialization process get split out into relationships and included - necessitating client-generated ids to link them together until they're saved on the server and given server-allocated ids.
However, we don't want these ids making their way to ActiveRecord methods like create and update (which erroneously cause Rails to attempt to find and update records with those ids - resulting in ActiveRecord::RecordNotFound exceptions being thrown).
We can't simply ignore or reject client-generated ids as part of the Strong Parameters permit method, because our PATCH requests can include a mixture of client-generated ids (for new associated records) and server-side ids (for existing associated records).
The solution we're currently going with is to define custom handlers for to_one and to_many that strip out ids that are conformant with a particular convention for client-generated ids, but I suspect this is likely a use-case others may encounter and that it would be beneficial for the library to support a regular expression that would cause matching ids to be stripped out:
JsonApi::Parameters.blacklist_ids = /^client_id_/
Once I've confirm you may be receptive to such a feature, I don't mind working on a pull request.
Thanks.