Skip to content

Cannot include same type twice #104

Open

Description

@richmolj

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.

Activity

  1. beauby commented on Jun 27, 2018

    @beauby
    Member

    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.

  2. richmolj commented on Jun 27, 2018

    @richmolj
    ContributorAuthor

    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.

  3. beauby commented on Jun 27, 2018

    @beauby
    Member

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

  4. richmolj commented on Jun 27, 2018

    @richmolj
    ContributorAuthor

    No, no sparse fieldset.

  5. beauby commented on Jun 27, 2018

    @beauby
    Member

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

  6. richmolj commented on Jun 27, 2018

    @richmolj
    ContributorAuthor

    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.

  7. richmolj commented on Jun 27, 2018

    @richmolj
    ContributorAuthor

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

  8. beauby commented on Jun 27, 2018

    @beauby
    Member

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

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

  9. richmolj commented on Jun 27, 2018

    @richmolj
    ContributorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions