Utilizing a query in a relation #3126
-
Hello everyone, I recently started using Drizzle in one of my projects. I am now in a situation, where I need to define a relation based on an sql query. Here is an example data structure:
My use-case is, that I want to be able to add tags to different entities (like 'user'). Instead of defining one tag table for each relation, I want to use one unified tag table, which contains the associated entity (column 'entity') in the form of the table name and the primary key value (column 'entity_id'). If I want to get all tags for an entity or a list of entities, I want to be able to just do something like:
I image it working similar to Hibernate Formular Annotation (https://medium.com/jpa-java-persistence-api-guide/hibernate-sub-query-with-formula-annotation-ace1085717c8). Does anyone know if something like this is possible with Drizzle or if it's planned for a future release? Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I came up with the following solution: Since my 'tag' table may consist tags for various entities in different tables, i created multiple relations for 'tag':
Unfortunately, I cannot use static strings in relations, which would result in something like this:
Since the above example with static strings is not possible, I then need to use a where condition when including tags in my query.
Maybe this might help someone else in the future. |
Beta Was this translation helpful? Give feedback.
I came up with the following solution:
Since my 'tag' table may consist tags for various entities in different tables, i created multiple relations for 'tag':
Unfortunately, I cannot use static strings in relations, which would result in something like this: