Skip to content

Utilizing a query in a relation #3126

Answered by nbastiantgc
nbastiantgc asked this question in Q&A
Discussion options

You must be logged in to vote

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':

export const tagRelations = relations(tagTable, ({one}) => ({
    user: one(usersTable, {
        fields: [tagTable.entityId],
        references: [usersTable.id]
    }),
    resource: one(resourceTable, {
        fields: [tagTable.entityId],
        references: [resourceTable.id]
    }),
// and so on...
}));

Unfortunately, I cannot use static strings in relations, which would result in something like this:

export const tagRelations = relations(tagTable, ({one}) => ({
    user: one(usersTable, {
        fields: [tagTable.entityId, …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by nbastiantgc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant