N
N
Explore posts from servers
DTDrizzle Team
Created by N on 12/21/2024 in #help
Self referencing composite primary key table
I'm trying to define a table where each organization can define a parent-child set of locations. Each location has a composite primary key (org, id) but i can't seem to get the self referencing foreign keys to work. Is there a way to accomplish what i'm trying to do? here's my code. Thanks!
export const locations = pgTable(
'locations',
{
id: varchar('id', { length: 60 }).notNull(),
orgId: varchar('org_id', { length: 60 }).notNull(),
name: varchar('name', { length: 255 }).notNull(),
isLeaf: boolean('is_leaf').default(false).notNull(),
parentId: varchar('parent_id', { length: 60 }),
parentOrgId: varchar('parent_org_id', { length: 60 }),
},
(table) => ({
pk: primaryKey({
columns: [table.id, table.orgId],
name: 'locations_pkey'
}),
}),
);

export const locationsRelations = relations(locations, ({ many, one }) => ({
parent: one(locations, {
fields: [locations.parentId, locations.parentOrgId],
references: [locations.id, locations.orgId],
relationName: 'parent_child',
}),
children: many(locations, {
relationName: 'parent_child',
}),
}));
export const locations = pgTable(
'locations',
{
id: varchar('id', { length: 60 }).notNull(),
orgId: varchar('org_id', { length: 60 }).notNull(),
name: varchar('name', { length: 255 }).notNull(),
isLeaf: boolean('is_leaf').default(false).notNull(),
parentId: varchar('parent_id', { length: 60 }),
parentOrgId: varchar('parent_org_id', { length: 60 }),
},
(table) => ({
pk: primaryKey({
columns: [table.id, table.orgId],
name: 'locations_pkey'
}),
}),
);

export const locationsRelations = relations(locations, ({ many, one }) => ({
parent: one(locations, {
fields: [locations.parentId, locations.parentOrgId],
references: [locations.id, locations.orgId],
relationName: 'parent_child',
}),
children: many(locations, {
relationName: 'parent_child',
}),
}));
4 replies
WWasp
Created by N on 10/12/2024 in #🙋questions
Page & Route specific metadata
Hey guys, currently the <meta /> tags are defined in the main.wasp file. Is there a way to define these metadata (eg. title and description) separately for each route dynamically? Thanks!
6 replies
WWasp
Created by N on 10/6/2024 in #🙋questions
Does wasp support preceeding route param eg. "/:lang/dashboard" ?
I want to have pages in different languages so i would like to set up the following routes: /:lang/dashboard /:lang/account ... If not, what can I do as a workaround? thanks!
6 replies