-
Notifications
You must be signed in to change notification settings - Fork 43
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
Problem with countable fields #194
Comments
What do you mean by "move"? |
When I use in schema
And try use it in request:
I have in response:
WithCount added count inside meta of relationship: |
That's not supported at the moment. The meta for the relationship that the count relates to feels like the best place to put it. It also makes sense from an implementation perspective, as the count is processed as part of the relationship. Presumably if the API client wants to treat it as an attribute it can normalize the payload however it sees fit once it receives it from the backend? |
I use Spraypaint Graphiti ORM on frontend for working with json:api, but it can't extract meta from relationships automatically. |
Ok so this would need a new feature to allow Eloquent aggregates as attributes. It's not a simple task though as it would involve making sure that the aggregate is always added to the model whenever the database is queried for that model. I can see it would be a useful feature though, but just can't give an ETA on when it might be implemented. However the next thing I'm likely to be working on is improvements to the combination of eager loading / sparse field sets / aggregates. The 3 are all interrelated as they all affect the database query that needs to be executed. |
It's not a "fluent" solution like the In one of our current apis, we're using Laravel's JsonResource to transform data into responses and this let's you use a |
Worth mentioned that Laravel JSON:API does have support for conditional attributes, via the resource class and documented here: https://laraveljsonapi.io/docs/2.0/resources/attributes.html#conditional-attributes So in other words, you'd be able to conditionally add the count attribute if it is set on the model. I put this feature in to match the Laravel Eloquent resources. I hadn't realised there was also a |
That's awesome Chris! I haven't used your json:api package since its revamp a while ago, so I'm going through the docs, tutorial, and Github issues to get caught up again. Guess I hadn't made it the conditional attributes section quite yet. Btw, this is an amazing package with an incredible amount of effort. If we decide to use it for a production app in the future, I'll do everything I can to assist with issues and PRs to give back, albeit by a small amount relative to the scope of the package. 👍 |
How to move
count
variables fromrelationships.*.meta.count
todata.*.attributes
?The text was updated successfully, but these errors were encountered: