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.

question: how would i annotate a relation that i only want to lookup if included

See original GitHub issue

For, example, let’s say events have associated users. So, we have

@JsonApiResource(type='events')
public class EventResource {
  @JsonApiRelation(serialize = SerializeType.ONLY_ID)
  UserResource user
}

So, I want to be be able to say /events/1 to do a query against the events service, which gives us back events with a userId, so then the resulting json has relationships with { "data": { "id": "1", "type": "users" } }

I also want to be able to say /events/1?include=user to do a query against the events service AND a query against the user service, so now i have a full user object to include, so a "included": [ { "id": "1", "type": "users", "attributes": {...} } ]

Even if there was a LoopIncludeBehavior of Always call a relationship's findManyTargets or findOneTarget if the field is included, that wouldn’t be quite right, because I actually want to utilize the userId that I already have off of the event object, almost like a /users/1 call, rather than do a query against the user service using the event id.

Any thoughts on how the framework wants me to go about doing this?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:21 (17 by maintainers)

github_iconTop GitHub Comments

2reactions
mohlekcommented, Jan 19, 2018

I was thinking of something like this:

@JsonApiResource(type='events')
public class EventResource {
   @JsonApiRelation( idField = "userId" )
   UserResource user

   String userId
}
1reaction
remmeiercommented, Jan 19, 2018

maybe to clarify for non-insiders, it could then look like:

@JsonApiResource(type='events')
public class EventResource {
   @JsonApiRelation
   UserResource user
   
  @JsonApiRelationId
   String userId
}

The user attribute would then still be managed & looked-up by crnk automatically. There would be no need to speciy relationship repositories for such cases.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Annotate queryset with whether matching related object exists
Assuming the middle model in your case of ManyToMany is called Favorite ... Thing.objects.annotate(favorited=Exists(is_favorited_subquery)).
Read more >
QuerySet API reference | Django documentation
Annotates each object in the QuerySet with the provided list of query expressions. An expression may be a simple value, a reference to...
Read more >
Question-Answer Relationship (QAR) | Classroom Strategies
The question-answer relationship (QAR) comprehension strategy teaches students ... require a reader to “Think and Search,” and that some answers can only be ......
Read more >
Annotating a Text - Reading and Study Strategies
Annotating is any action that deliberately interacts with a text to enhance the reader's understanding of, recall of, and reaction to the ...
Read more >
Create and manage relationships in Power BI Desktop
You can see a preview of the data in each table and as you select different columns, the window automatically validates the relationship...
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