You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to add a media relation to my invoices table.
The media table can point to any table via the media.attachableType column.
In this case the attachable type is "invoice" which I want to hard code into the relation definition.
The media.attachableId column references the PK of the invoices table.
Is this supported in any way atm?
SELECT*FROM"invoices"INNER JOIN"media"ON (
"media"."attachable_type"='invoice'-- Hard coded valueAND"media"."attachable_id"="invoices"."id"
)
exportconstmedia=pgTable('media',{id: serial('id').primaryKey().notNull(),attachableType: varchar('attachable_type',{length: 255}).$type<mediaSDK.MediaType|(string&{})>(),attachableId: integer('attachable_id'),// Snip...createdAt: timestamp('created_at',{withTimezone: true,mode: 'date'}).defaultNow(),updatedAt: timestamp('updated_at',{withTimezone: true,mode: 'date'}).defaultNow(),},(table)=>({mediaAttachabletypeAttachableidPathUnique: unique('media_attachabletype_attachableid_path_unique',).on(table.attachableType,table.attachableId,table.path),}),)exportconstinvoices=pgTable('invoices',{id: serial('id').primaryKey().notNull(),// Snip...createdAt: timestamp('created_at',{withTimezone: true,mode: 'date'}).defaultNow(),updatedAt: timestamp('updated_at',{withTimezone: true,mode: 'date'}).defaultNow(),})exportconstinvoiceRelations=relations(invoices,({ one })=>({deal: one(deals,{references: [deals.id],fields: [invoices.dealID],}),tenant: one(tenants,{references: [tenants.id],fields: [invoices.tenantID],}),media: one(media,{references: [media.attachableId,media.attachableType],fields: [invoices.id,'invoice'],// I want to hard code this value}),}))
The text was updated successfully, but these errors were encountered:
Describe what you want
I want to add a
media
relation to my invoices table.The media table can point to any table via the
media.attachableType
column.In this case the attachable type is
"invoice"
which I want to hard code into the relation definition.The
media.attachableId
column references the PK of theinvoices
table.Is this supported in any way atm?
The text was updated successfully, but these errors were encountered: