Skip to content

HasManyThrough always returns data:null but includes returns data #491

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

Closed
sarahentzel opened this issue Apr 4, 2019 · 11 comments
Closed

Comments

@sarahentzel
Copy link

sarahentzel commented Apr 4, 2019

Description

Running the JsonApiDotNetCoreExample, http://localhost:1479/api/v1/articles/1/tags returns {"data":null} but http://localhost:1479/api/v1/articles/1?include=tags returns the tags:

{  
   "data":{  
      "attributes":{  
         "name":"Article 1 about good stuff"
      },
      "relationships":{  
         "author":{  
            "links":{  
               "self":"http://localhost:1479/api/v1/articles/1/relationships/author",
               "related":"http://localhost:1479/api/v1/articles/1/author"
            },
            "data":{  
               "type":"authors",
               "id":"1"
            }
         },
         "tags":{  
            "links":{  
               "self":"http://localhost:1479/api/v1/articles/1/relationships/tags",
               "related":"http://localhost:1479/api/v1/articles/1/tags"
            },
            "data":[  
               {  
                  "type":"tags",
                  "id":"1"
               }
            ]
         }
      },
      "type":"articles",
      "id":"1"
   },
   "included":[  
      {  
         "attributes":{  
            "name":"Good Stuff"
         },
         "type":"tags",
         "id":"1"
      }
   ]
}

Environment

  • JsonApiDotNetCore Version: I've tried using release 3.0.0, develop and master branches
  • Other Relevant Package Versions:
@sarahentzel
Copy link
Author

@wisepotato Were you able to get data with api/v1/articles/1/tags as well as api/v1/articles/1?include=tags (after you fixed it?)

@wisepotato
Copy link
Contributor

wisepotato commented Apr 11, 2019

Is there a specific issue you are referring to? This could very well not be implemented yet, my issue was about tags needing to be filtered via the ResourceDefinition<Tag>

@sarahentzel
Copy link
Author

It seems like it has been implemented based on issue #453 which sounds like the same issue solved.

@maurei
Copy link
Member

maurei commented Apr 23, 2019

@sarahentzel did you manage to work this out? Is this still an issue?

@sarahentzel
Copy link
Author

It is still an issue.

@maurei
Copy link
Member

maurei commented Apr 23, 2019

OK, we're currently working on releasing a new version, should be finished somewhere this week. Will look into this after that. If you could meanwhile make a branch/pr with a test that reproduces the exact error, it would greatly aid me in quickly fixing it :-)

@sarahentzel
Copy link
Author

Permission to json-api-dotnet/JsonApiDotNetCore.git denied to sarahentzel

@wisepotato
Copy link
Contributor

You can fork the current repository, and then create a pull request, it will show us the test

@rjacquemin
Copy link

rjacquemin commented May 8, 2019

we have same kind of issue

using relation HasManyThrough
works fine with HasMany or HasOne

calling our endoint give all relations properly mapped using
image

calling "related": "/api/admin/packs/2/genres"
image

calling with include
image

I can see EF is generating same queries in my console
Those queries make sens and retrieve the right data when I execute manually

I suspect some issue in the mapping logic
image

@theandrewcosta
Copy link

@rjacquemin @wisepotato

Looks like the issue is in ResourceGraph.cs

image

Looks like the variabe "navigationProperty" does not reflect the one specified by [HasManyThrough(nameof(...)] attribute on the original entity.

@bart-degreed
Copy link
Contributor

bart-degreed commented May 13, 2020

On the current master branch, I cannot reproduce the originally posted problem.
Any reason not to close this?

GET http://localhost:1479/api/v1/articles/1/tags HTTP/1.1
{
  "links": {
    "self": "http://localhost:1479/api/v1/articles/1/tags"
  },
  "data": [
    {
      "type": "tags",
      "id": "1",
      "attributes": {
        "name": "vrre051f7t"
      },
      "links": {
        "self": "http://localhost:1479/api/v1/tags/1"
      }
    }
  ]
}
GET http://localhost:1479/api/v1/articles/1?include=tags HTTP/1.1
{
  "links": {
    "self": "http://localhost:1479/api/v1/articles/1?include=tags"
  },
  "data": {
    "type": "articles",
    "id": "1",
    "attributes": {
      "name": "None for you Glen Coco"
    },
    "relationships": {
      "author": {
        "links": {
          "self": "http://localhost:1479/api/v1/articles/1/relationships/author",
          "related": "http://localhost:1479/api/v1/articles/1/author"
        }
      },
      "tags": {
        "links": {
          "self": "http://localhost:1479/api/v1/articles/1/relationships/tags",
          "related": "http://localhost:1479/api/v1/articles/1/tags"
        },
        "data": [
          {
            "type": "tags",
            "id": "1"
          }
        ]
      },
      "identifiableTags": {
        "links": {
          "self": "http://localhost:1479/api/v1/articles/1/relationships/identifiableTags",
          "related": "http://localhost:1479/api/v1/articles/1/identifiableTags"
        }
      }
    },
    "links": {
      "self": "http://localhost:1479/api/v1/articles/1"
    }
  },
  "included": [
    {
      "type": "tags",
      "id": "1",
      "attributes": {
        "name": "vrre051f7t"
      },
      "links": {
        "self": "http://localhost:1479/api/v1/tags/1"
      }
    }
  ]
}

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

No branches or pull requests

6 participants