Skip to content

HasManyThrough relationships always return empty data:[] array on GET #453

Closed
@XaserAcheron

Description

@XaserAcheron

Description

Seems when trying to GET a record that contains a HasManyThrough relationship, it returns an empty data: [] array even though I'm not specifying ?include. Meanwhile, HasMany relationships seem to work just fine.

Here's a somewhat-anonymized sample response (comments added) which hopefully illustrates the issue:

{
    "data": [
        {
            "attributes": {
                "title": "Sample Article",
                "text": "...",
                "create-date": "2018-08-14T16:19:13.653"
            },
            "relationships": {
                "comments": { // HasMany relationship (works correctly)
                    "links": {
                        "self": "/api/articles/1/relationships/comments",
                        "related": "/api/articles/1/comments"
                    }
                },
                "authors": { // HasManyThrough relationship
                    "links": {
                        "self": "/api/articles/1/relationships/authors",
                        "related": "/api/articles/1/authors"
                    },
                    "data": [] // <-- this shouldn't be here
                }
            },
            "type": "articles",
            "id": "1"
        }
    ]
}

To clarify, the article has authors, and they're returned successfully when I ?include them, so this empty array is a bit of a red herring that's monkeying up the client application (ember-data).

I did stumble across this issue and double-checked to make sure I'm not initializing any lists anywhere, and it doesn't seem so. Not sure what else, if anything, might be configured differently in my project versus the repo example, so I'm a bit stumped.

Environment

  • JsonApiDotNetCore Version: 3.0.0
  • Other Relevant Package Versions: [?]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions