miLibris / flask-rest-jsonapi

Flask extension to build REST APIs around JSONAPI 1.0 specification.
http://flask-rest-jsonapi.readthedocs.io
MIT License
597 stars 153 forks source link

issue using 'include' to request multiple related resources #29

Closed nemmons closed 7 years ago

nemmons commented 7 years ago

Hi there. I'm having trouble requesting multiple related resources and i can't tell if i'm misunderstanding ember-data or the API spec or if there's a problem with the backend library i'm using.

Example: Articles hasMany Comments, Comments belongsTo Author, Comments belongsTo Approver.

I want to load a specific Article along with all Comments and for each Comment, the Author and Approver.

If i do /articles/1?include=comments,comments.author,comments.approver, i get the Article with the Comments and the Approvers, but no Authors.

If i do /articles/1?include=comments,comments.approver,comments.author, i get the Article with the Comments and the Authors, but no Approvers.

I am very confident that i have the Schemas set up correctly, if i remove either of the 'comments.*' options from the query string, the data for the other one is loaded fine. The only issue occurs when i try to ask for both at the same time. I believe that JSONAPI should support this so i believe this is a bug?

Thanks for any help you can provide!

akira-dev commented 7 years ago

Try this /articles/1?include=comments.author,comments.approver

Make sure your schemas are well configured and your data are accessible by your schemas.

nemmons commented 7 years ago

Thanks for the suggestion, but I get the same issue with that querystring. If i list comments.author first, i only get the data for the Author. If i list comments.approver first, i only get the data for the Approver. This makes me very confident that my schemas are correct and that my data is accessible, because the issues only occur when i try to request both deep associations at the same time.

nemmons commented 7 years ago

Ah. I spoke too soon. Yes, the query string you suggested is working for me now. Thanks very much for the help, and thanks very much for this incredibly helpful flask extension!

tzimme commented 7 years ago

I ran into the same problem and unless i'm missing something other then leaving out 'comments,' , the suggested query also only incudes one of the two relationships, depending on its order

in my case the relationships are like /author/123/?include=articles.comments,articles.ratings