-
-
Notifications
You must be signed in to change notification settings - Fork 158
Relationship Data - missing or by design? #218
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
Comments
I think this is an oversight. In the case of a dependent HasOne relationship we can include this easily and I think maybe we should. However, on the independent side of a HasOne (in the case of a 1:(0-1) relationship) we will not include this because it would necessitate a SQL JOIN and would be unexpected behavior. |
I think we need to do some setup when we build the ContextGraph so we don't do any extra request-time reflection. That would involve modifying the ContextGraphBuilder to set some HasOneAttribute.IsDependent and maybe even a reference to the RelationshipId PropertyInfo. Then the DocumentBuilder will need to pull out the value. With tests, I would expect it to take me a couple hours. I'd also be happy to work with you if you want to take a stab at it. |
Ha, I just deleted my comment. I was going to just try messing with the DocumentBuilder Will start to get me used to the code if nothing else. |
A very quick hack was to:
It assumes that when you have a Very hacky, and I probably need to consider more complex models if I run in to them, but it quickly unblocked the clientside dev. FWIW, I started to go down the rabbit hole of ContextGraph changes but quickly came back up for air before I sunk a day on it. :) Thanks for pointing me in the right direction for now. |
I currently have the need to include "data" (without attributes) for each relationship by default. From what I could tell, the only thing preventing this is the check in DocumentBuilder.cs in the AddRelationships() method: |
The only challenge I see is this requirement from the spec (let me know if I'm just missing something here):
Without that check, I think there are conditions under which we would no longer comply with the specification. As a framework we have a strict constraint of complying with the spec by default. However, I 100% believe we should make it simple for applications to deviate as needed. A possible option is to make |
Ah, yes sorry my mistake. You’re correct. |
…her than only when "include" for that relationship is set.
…n resource relationships with id and type set.
#218 Defaults data to be included in relationships rather than only w…
in all requests for the dependent side of the relationship by default
Hy. I'm using Version 2.1.0 and would like to receive the relationships data object an every GET request. Is there any possibility to get only the { type, id } relationship infos without the included object? some example:
|
@wurmrobert please try the latest version (2.2.4) that fixes this issue. If that does not work for you, let me know. |
@jaredcnance i have updated to the latest version (2.2.4) but i still do not get the relationships data object (i only obtain the links object). Do i have to put any options? |
@wurmrobert this is working for me running the example app. And no configuration options are required, this is default behavior. As previously mentioned, we will not perform a join to get dependent relationship side of a 1:(0-*) relationship from the independent side. Can you answer a few questions to help me understand your setup:
|
@jaredcnance thanks a lot for your help! my models:
With Postico i can see that device has a relation to a customer: |
public class Device: Identifiable {
[Attr("mac_address")]
public string MacAddress { get; set; }
[HasOne("customer")]
public virtual Customer Customer { get; set; }
public int CustomerId { get; set; } // we need EF to set this property
} |
I am unable to reproduce this behavior (we also have tests that run this request). A few other things you might check:
|
Really strange.
I have put the source to a public repo: https://github.com/wurmrobert/jsonapi-graphql-example The startup class:
|
Hy @jaredcnance. After setting customerId as optional:
the GET request returns all data relationships. But on the POST Method dotnet quits unexpectedly. |
…hen "include" for that relationship is set.
…tionships with id and type set.
#218 Defaults data to be included in relationships rather than only w…
in all requests for the dependent side of the relationship by default
Should I always see relationship data, regardless of link config or include query?
By this, I mean
/items
currently produces:If I include
owner
(/items?include=owner
):Even when I am not asking for
includes
(or iflinks
are turned off), I was expecting the relationships to always have data:Is this expected behavior or am I potentially missing something on my model?
Based on http://jsonapi.org/format/#document-resource-objects and their
{ article }
snippet, it suggests data should be there.. I must be missing something somewhere?The text was updated successfully, but these errors were encountered: