Skip to content
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

Cannot include same type twice #104

Open
richmolj opened this issue Jun 27, 2018 · 9 comments
Open

Cannot include same type twice #104

richmolj opened this issue Jun 27, 2018 · 9 comments

Comments

@richmolj
Copy link
Contributor

Imagine a book has multiple authors. You want to fetch an author, their books, and all the other co-authors for those books.

/authors/123?include=books.authors

Currently, if you do this, it will blow away all relationships on books instead of rendering correctly.

@beauby
Copy link
Member

beauby commented Jun 27, 2018

What do you mean by "blow away"? I would expect this to include the base author (id=123) in the primary data, and all their books, as well as all their co-authors in the included section. Moreover, I would expect every book in the response to have a fully populated authors relationship.

@richmolj
Copy link
Contributor Author

I would expect every book in the response to have a fully populated authors relationship.

This would not be the case. The relationships are removed.

@beauby
Copy link
Member

beauby commented Jun 27, 2018

Are you providing a sparse fieldset as well? Otherwise that would be a bug.

@richmolj
Copy link
Contributor Author

No, no sparse fieldset.

@beauby
Copy link
Member

beauby commented Jun 27, 2018

Could you provide a failing spec for this if you have one handy? I'll investigate and fix right now.

@richmolj
Copy link
Contributor Author

Not one for this repo but next best thing. This reproduces in my sample app. If you run bin/rspec spec/api/v1/employees/index_spec where that binding.pry is, you'll see that no included is coming back at all (in a different scenario ive seen included come back but relationships missing from one of the included members.). Remove the extra include of .employees and it will work again.

@richmolj
Copy link
Contributor Author

Otherwise it will be a little while before I can get a spec for this repo.

@beauby
Copy link
Member

beauby commented Jun 27, 2018

has_many :employees (plural)
vs
create(:position, employee: employee1) (singular employee)

Does the created resource actually respond to .employees (plural)?

@richmolj
Copy link
Contributor Author

Ah, yes, that's an eventual issue but not relevant to the immediate one. It's originally position belongs_to employee, but as part of the commit I made it have many employees as well (at one point I was thinking it might be has-many specific). So it responds to employee and employees both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants