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
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
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.
- 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.
