You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This will return Parents, but set the child as undefined if the other_thing value doesn't match. However what I want, is some way to exclude the parent if it can't find that child.
I understand that the easiest way to achieve this would be to flip how I query the resources and query for the child. Eg:
The reason that I want to have some way of filtering / sorting the parent based off the child, is because I have a dropdown with a whole bunch of fields that a user can choose to have their results sorted by. This includes fields from the parent and the child.
For sorting I guess I could change the resource thats queried based off the sort field. Although it does complicate the UI having to accept different models when rendering certain components.
However when it comes to filtering, there are situations where I want to stack multiple filters and that wouldn't work.
The text was updated successfully, but these errors were encountered:
I just defined attributes on the parent resource and used a join. eg:
classParentResource < ApplicationResource# .... Other codesort:other_thing,:stringdo |scope,direction|
scope.joins(:child).order("child.other_thing"=>direction).select("parent.*","child.other_thing")endend
Same idea should work with filters I believe.
Man Graphiti is awesome!
I would close this issue, but I just have one last question with this approach. The select seems to be required as I'm referencing the child value in the order clause. I had to have the parent.* added in to make sure it pulls the parent fields. However this ignores the fieldset requested by the client if the client wants sparse fields.
Is there anyway to pull the select fields within the sort block?
I couldn't quite work out if this can be done by reading the docs / playing around with some requests.
I'm looking for a way to filter / sort a parent resource based off a child association's field.
I think an example might be the easiest way to illustrate what I'm wanting to do.
Say you have 2 graphiti resources:
Now on the frontend, using Spraypaint to query.
What I would like to do, is something like this:
This will return Parents, but set the child as undefined if the other_thing value doesn't match. However what I want, is some way to exclude the parent if it can't find that child.
I understand that the easiest way to achieve this would be to flip how I query the resources and query for the child. Eg:
The reason that I want to have some way of filtering / sorting the parent based off the child, is because I have a dropdown with a whole bunch of fields that a user can choose to have their results sorted by. This includes fields from the parent and the child.
For sorting I guess I could change the resource thats queried based off the sort field. Although it does complicate the UI having to accept different models when rendering certain components.
However when it comes to filtering, there are situations where I want to stack multiple filters and that wouldn't work.
The text was updated successfully, but these errors were encountered: