Using no attributes to use a parent_type / parent_id style table as a join table
I have this table:
And in Group I want to query all Outcrop through this table..
I thought I had done this before and I am currently stuck here (in
relationships
of Group
):
Solution:Jump to solution
Ok for anyone else coming across this post because they want to use no_attributes? true to do some complex mapping, here is the gist of it:
- You can do a has_many or has_one to any App.Domain.Resource with some prereqs:
- There must be a tangible path mapped up back to what you want
- In my case I had...
4 Replies
I guess I need to put in another relationship in the Group resource that points at the join table to replace the what_to_put_here
This is a little bit closer, but it is also not a way to get actual Outcrop out 😄
the bottom one is the correct way to map up the link to the lithostrat outcrop link table at least
how to utilize it as a join table to get outcrops?
maybe better to set up a calc to do that? My goal here is that I want to expose group.outcrops{..} on the graphql side of things
You can have paths in parent
expr(parent(through.thing_id) == ...)
does that help?Does that help me select the outcrop?
I will iterate a little here
Solution
Ok for anyone else coming across this post because they want to use no_attributes? true to do some complex mapping, here is the gist of it:
- You can do a has_many or has_one to any App.Domain.Resource with some prereqs:
- There must be a tangible path mapped up back to what you want
- In my case I had
- Outcrop
- LithostratOutcropLink (with parent_id == outcrop, target_type == group|member|formation and target_id == the id of the group etc)
- Group
Solution to put on Group:
This works because outcrop has:
And that lets the filter traverse this relation and relate the ids etc with the source resource, using this middle table as an impromptu jointable.