Having some trouble wrapping my head around how I could use Polymorphic associations like this.
Say I have a abstract
Then say I have all kinds of variations of posts like
I want to use the
Posts schema as the common abstract record and then create the respective record with its more specific values.
That way I can do a simple query on all
Posts where I need the common values regardless of their specific type but without doing complex
The common examples give the example of using comments on posts. The issue I’m running into is that is backwards for my type of associations and I’m not sure how I can flip it.
Ideally I will be able to create a record for any of the Complex schemas and have created a Abstract record that abstracts our “common fields” for that given Complex schema and have created a relation between the two records that allow for me to be able to query across all the complex schemas without building large and difficult to manage a UNION query to get all the common fields for our different complex schemas (IE just look up the Abstract table).
Issues I’d like to avoid:
- Having to create large manifest of belongs_to/has_n per N number of columns for N number of Complex schemas my system may end up with.
- Having to create and manage a large complex
UNIONquery to look over all of the Complex schemas to get an aggregation of all the complex schemas. (ie looking up counts for all complex schemas ect.)
- Coupling logic of the abstract layer to the complex layer. Say one complex schema has a wildly different need then that of another complex schema. I don’t want that concern to bleed into the abstract layer
I also created an example repo that I’m gonna use to explore this issue.