You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At the moment an Eloquent relation (e.g. has-many) uses the same defaults as when querying a resource index.
For example, if a posts resource has default paging parameters, these will be applied both for GET /posts and GET /users/1/posts.
This is generally great as it is nice and consistent, but there are scenarios where you might want different defaults (or no defaults) for a relationship.
For example, say there's a tags resource. There might be 100s of tags, so when you're reading them from GET /tags it would make sense to have default paging params so that a client does not list all tags at once. However, when doing GET /posts/1/tags realistically there might only be a few to 10s of tags for the post... so it doesn't make sense to always force paging on the relationship endpoint. We therefore need the relationship to remove the default paging params from the tags adapter before using that adapter to process the query.
We therefore need to allow a developer to change the defaults for relationships, for the following:
paging
sort
An initial concept design would be to define these on the relationship objects. So for example, on the posts adapter:
Then add an equivalent method to the Eloquent adapter that returns a new instance without default paging - that the relationship can call before using the adapter to query the relationship. It is important that the method returns a new instance because adapters are singletons in the JSON API container.
The methods to add are:
withoutDefaultPaging()
withDefaultPaging($paging)
withoutDefaultSort()
withDefaultSort($sort)
Best to call them withDefault* because we are only overriding the defaults... if the client has sent page parameters, the response should be paged even if the default is not to page.
The text was updated successfully, but these errors were encountered:
At the moment an Eloquent relation (e.g. has-many) uses the same defaults as when querying a resource index.
For example, if a
posts
resource has default paging parameters, these will be applied both forGET /posts
andGET /users/1/posts
.This is generally great as it is nice and consistent, but there are scenarios where you might want different defaults (or no defaults) for a relationship.
For example, say there's a
tags
resource. There might be 100s of tags, so when you're reading them fromGET /tags
it would make sense to have default paging params so that a client does not list all tags at once. However, when doingGET /posts/1/tags
realistically there might only be a few to 10s of tags for the post... so it doesn't make sense to always force paging on the relationship endpoint. We therefore need the relationship to remove the default paging params from the tags adapter before using that adapter to process the query.We therefore need to allow a developer to change the defaults for relationships, for the following:
An initial concept design would be to define these on the relationship objects. So for example, on the
posts
adapter:Then add an equivalent method to the Eloquent adapter that returns a new instance without default paging - that the relationship can call before using the adapter to query the relationship. It is important that the method returns a new instance because adapters are singletons in the JSON API container.
The methods to add are:
withoutDefaultPaging()
withDefaultPaging($paging)
withoutDefaultSort()
withDefaultSort($sort)
Best to call them
withDefault*
because we are only overriding the defaults... if the client has sent page parameters, the response should be paged even if the default is not to page.The text was updated successfully, but these errors were encountered: