question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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: [?]

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jaredcnancecommented, Dec 5, 2018

Okay no worries. It’s probably not your model then and it’s likely an issue at the serialization later of the framework. I’ll try to work on it this week.

0reactions
XaserAcheroncommented, Dec 6, 2018

Yup, that was it. Just made a PR. 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Laravel Eloquent HasManyThrough returning empty array
I am having trouble getting a query from HasManyThrough relation in Eloquent. These are my tables. PAGES. id; columns; slideshow_fk. SLIDESHOWS.
Read more >
HasManyThrough relationship returning empty array
HasManyThrough relationship returning empty array. Hello! I have a database that has several tables, but we only need to focus on 3: providers....
Read more >
Laravel hasManyThrough returning empty array-laravel
According to the details you have provided it should be like this. public function user_income() { return $this->hasManyThrough( 'App\IncomeTable', ...
Read more >
Eloquent: Relationships
A one-to-one relationship is a very basic type of database relationship. ... The phone method should call the hasOne method and return its...
Read more >
Empty array laravel. This validation is really simple if you read
Laravel API Resource not returning data with one to many relationship. ... Getting empty array on Laravel eloquent relationship HasManyThrough.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found