GetRelationshipAsync returns RelationshipNotFoundException
See original GitHub issueDESCRIPTION
After upgrading to v4 we noticed that GetRelationshipAsync now throws an exception.
This was working…
await base.GetRelationshipAsync(id, "client-discount-details", cancellationToken);
Current error
Relationships seem correct.
The entity
TIA.
VERSIONS USED
- JsonApiDotNetCore version: 4.0.0
- ASP.NET Core version: 3.1
- Entity Framework Core version: 3.1.10
- Database provider: Sql Server
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Async SQLalchemy: accessing eagerly-loaded empty ...
I am using sqlalchemy + asyncpg, and 'selectin' eager loading. I have Person items that have one-to-many relationships with Friends. I insert a ......
Read more >cypher query returning UnknownError: node [...] not ...
I discovered that some cypher queries using shortest path fail for specific input, while at the same time work well with others.
Read more >Getting started with continuous integration for Nest.js APIs
Learn how to build RESTful APIs with Nest.js, a Node.js framework built with TypeScript, and automate testing using CircleCI.
Read more >Implementing CRUD Operations with One-to-Many ...
With this setup, we can easily retrieve all TodoItem entities associated with a particular TodoList entity by querying the todoItems property of ...
Read more >API with NestJS #75. Many-to-many relationships using raw ...
We look into a more complex relationship called many-to-many and implement it in our NestJS project using raw SQL.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Cloning sounds like a separate concern to me that is independent from the JsonApiDotNetCore pipeline. So I would keep it simple. Just add a class that provides the clone operation, taking
DbContext
as dependency and call that from within your service.How that can be implemented is described here. I would first execute a LINQ query with
.Include()
s to fetch the tree in a single operation, usingAsNoTracking()
and clear out all IDs afterwards, so they are re-assigned on save. Then add the root object to theDbContext
and save it.The reason I believe going through the JsonApiDotNetCore pipeline for the individual steps is not the best solution, is because several parts in the pipeline need to be re-aligned in each step in order for that to work, which can be hard to get right. And to me it seems there is no real benefit in going through all that. The middleware normally analyzes the kind of request and sets context data in
IJsonApiRequest
, which is consumed from a service method (but also from the query string parsers). So if you get an incoming request for /books, but then in theGet()
service method, callbase.GetSecondary(...)
(which would normally match /shop/1/books), then the context is wrong. So the parsed query strings do not match what the service executes, the wrong resource definition callbacks are invoked etc. To summarize, the expectation that you can just call any base service method from any other service method is unjustified and I wouldn’t go there, unless it has huge benefits.Fun fact: I’m actually going there for implementing atomic operations, which enables to batch multiple changes in a single request. And for that to work, I need to update
IJsonApiContext
andITargetedFields
for each operation within the list to make things work.It looks like you’re passing a hardcoded relationship name “client-discount-details”. This value is only used to produce the error message, as we assume it matches with the incoming HTTP request. If your goal is to fetch a relationship different from the one coming from the request, you’ll also need to set the
JsonApiRequest.Relationship
property. You can inject the interface and cast to overwrite the property. Get the value usingIResourceContextProvider
. Hope that helps.