Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix the inclusion of relations #127

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

Merged
jsenecal merged 1 commit into django-json-api:develop from adfinis:develop
Oct 13, 2015
Merged

Fix the inclusion of relations #127

jsenecal merged 1 commit into django-json-api:develop from adfinis:develop
Oct 13, 2015

Conversation

Copy link
Contributor

@schtibe schtibe commented Oct 12, 2015

When getting a list and including data from the models in the list, only
the related data of the first model in the list was included

Explanation:
Let's assume a Model M that has a foreign key type referencing Type. Now we get a list of M which have different types and include the types (?include=type), only the Type of the first reference will be included, because of line 417.

When getting a list and including data from the models in the list, only
the related data of the first model in the list was included
Copy link
Member

jerel commented Oct 12, 2015

@jsenecal I'm 👍 on this if you want to review and merge

Copy link
Member

Have you tried setting a path in the include parameter? Like so: include=blog.author otherwise I don't understand your issue

Copy link
Contributor Author

schtibe commented Oct 12, 2015

Assuming table Person:

pk fruit (fk to Fruit) Person
1 1 John
2 1 Jack
3 2 Jill

and table Fruit:

pk name
1 apple
2 banana

Now let's do GET /api/v1/person?include=fruit which is programmed to return all persons

Gives roughly following result (I wrote this from memory ):

 {
 "data": [{
 "type": "persons",
 "id": 1,
 "attributes": { "name": "John" },
 "relationships": {
 "fruit": {
 "data": { "type": "fruit", "id": "1" }
 }
 }
 },
 {
 "type": "persons",
 "id": 2,
 "attributes": { "name": "Jack" },
 "relationships": {
 "fruit": {
 "data": { "type": "fruit", "id": "1" }
 }
 }
 },
 {
 "type": "persons",
 "id": 3,
 "attributes": { "name": "Jill" },
 "relationships": {
 "fruit": {
 "data": { "type": "fruit", "id": "2" }
 }
 }
 }
 # so far so good, now here it gets interesting
 ],
 "included": [{
 "type": "fruit",
 "id": 1,
 "attributes": {
 "name": "apple"
 }
 }]
 # banana is missing, even though the person 3 references it
 },

Copy link
Member

Ok, so I'm trying to understand your last comment @schtibe - why would /api/v1/apple return person objects ?

Anyways - I'll merge this as the change makes sense and somewhat seem to work for me too but I'll try to make tests to validate the behavior when I fix #126

jsenecal added a commit that referenced this pull request Oct 13, 2015
@jsenecal jsenecal merged commit c2c53bb into django-json-api:develop Oct 13, 2015
Copy link
Contributor Author

schtibe commented Oct 13, 2015

@jsenecal oh, sorry this is an error. It would be /api/v1/person of course.

Copy link
Member

jerel commented Oct 13, 2015

@schtibe I also ran into a strange bug with included records today. Could you take a look at my PR and see if it's related to the behavior you were seeing?

Edit: mentioned the wrong person by accident.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /