-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add include id relation only option and smart related link behavior based on that #23
Comments
Hey @bterkuile, thanks for the thoughts here. Unfortunately I don't think the hash syntax you've suggested is compatible with the JSON-API spec, and I wouldn't want to introduce a custom syntax like that into this gem. The I think I see what you're saying though, it's basically that things are too slow because of all the internal object allocations and lookups? I have been encountering some performance problems with jsonapi-serializers recently, so I definitely want to address that and optimize the internal recursion at some point. I think you're right—a big optimization we could make would be to have a way to do ID lookups without having to load the full object. It may be as simple as adding a hint like |
That is where the hash syntax is for, indicating to use the child id from the object itself without loading relation itself. I think after merging my current open pull request the performance already will increase a lot 😄 |
You know what, I realize this is basically the same as #8 — we could do something automatic, like if you provide an |
That avoids having to have the new hash syntax, but still gets what you want (I think). |
I think that could be it! |
I'll take a look at your PR today, I think that should get in before moving forward with this. |
A conceptual implementation that automatically adds the id of the parent object if it can be inferred is done in: https://github.com/bterkuile/jsonapi-serializers/tree/feature/include_has_one_id_if_present_on_object This breaks some existing specs, but I think in a good way. aka explicitly add |
Consolidating this issue into #30 |
I am experimenting with this gem in situations with heavily nested structures. The
include:
option of the serializer handles the full include stack. In many cases I would want only to add thetype
andid
in therelationships
section, but do not need to include the objects itself (I think, but want to test the idea over here). A possible scenario would beMeaning I want to serialize posts, include the comments and the comments' annotations (sorry for the bad inspiration in finding good examples, it is about the idea) but only want to include the id references of the comments' tags and user and of the post's author.
The resulting data should look something like:
Would this make sense at all? And if yes would the hashtag prefix notation be the way to go in this? This would at first need the addition to specify the hashtag relations, and a non trivial id lookup relationship option:
I am willing to help implementing this if the idea behind it makes sense. Since I am really new to JSONAPI I would like to know first if there is not some other point I am missing. This in my idea would dramatically increase performance by removing the need to fetch all the associated objects. It would also solve the case where the same record is included in a different context bug (other issue).
For people more comfortable with the full javascript object notation in stead of the coffeescript version, here the payload as javascript:
Thanks for the effort!
The text was updated successfully, but these errors were encountered: