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
Support shallow routing for belongs_to? #180
Comments
The belongs_to is there for nested routes. If your API returns link definitions like the jsonapi.org spec provides, the client can follow those links without having to declare them in code. Personally, I don't like to nest routes because you are required to know the parent's id in order to access the child resource(s). Instead, it could be a flat, root resource with a filter by the parent id (which is totally optional). Is the issue that you have both a flat and nested resource together? |
Yes all of our apis have the so for instance we have something like INDEX, CREATE and SHOW, UPDATE, DESTROY Currently to support that I need
|
Same issue here. Nested routes helps to reason about a resource in its context (an |
My APIs use the same structure as described in other comments. I'd really like to see this implemented. Is there anything I/we could do to get this going? |
Has anybody tried adding link information to their serializers, as @chingor13 mentioned? I have not, but it sounds like that might be a pretty good workaround until this is supported. I'd love to know whether that works... if I get a chance, I'll try it out. Obviously supporting shallow nesting without links would be great too. However, I could also see just dropping all forms of automagic URL construction other than Perhaps customizable procs that take parameters (which would vary depending on the action) and return a URL... for instance (if you had some odd routes): class Invoice < Base
destroy_with ->(invoice) { [:delete, "/orders/#{invoice.order_id}/invoices/#{invoice.id}"] }
create_with ->(invoice) { [:post, "/orders/#{invoice.order_id}/new_invoice"] }
list_with ->(parent) { # if API provides '/users/:id/invoices' and '/orders/:id/invoices'
case parent
when Order; "/orders/#{parent.id}/invoices"
when User; "/users/#{parent.id}/invoices"
end
}
update_with ->(invoice) { :patch, "/orders/#{invoice.order_id}/invoices/#{resource.id}"]
end |
But then again, just supporting shallow nesting should probably be a simple flag on the model! ;) class Invoice < Base
belongs_to :order, shallow_paths: true
end |
Any update on this ? |
decouple attributes and path params fix JsonApiClient#180
decouple attributes and path params fix JsonApiClient#180
Unless I am mistaken, it seems belongs_to resources only support nested routes for find, update and delete. Has there been any thought about supporting shallow routes? Currently in have to create two classes: one with the belongs_to defined and the other without.
The text was updated successfully, but these errors were encountered: