Error: column "deletedAt" does not exist
KenjiGinjo opened this issue · comments
Kenji commented
// orm query
await db.comment.select('id', {
subcomments: (q) => q.subcomments.select('id'),
})
This query generated sql is
// generated raw sql
SELECT "comment"."id",
COALESCE("subcomments".r, '[]') "subcomments"
FROM "comment"
LEFT JOIN LATERAL
(SELECT json_agg(row_to_json("t".*)) r
FROM
(SELECT "subcomments"."id"
FROM "comment" AS "subcomments"
WHERE "subcomments"."deleted_at" IS NULL
AND "subcomments"."root_id" = "comment"."id") AS "t"
WHERE "deletedAt" IS NULL) "subcomments" ON TRUE
WHERE "comment"."deleted_at" IS NULL
deletedAt is wrong, deleted_at is right.
Kenji commented
related Table orchidORM config and Prisma schema
export class TableComment extends BaseTable {
public readonly table = 'comment';
public readonly softDelete = true;
public columns = this.setColumns((t) => ({
id: ...,
createdAt: ...,
updatedAt: ...,
deletedAt: ...,
rootId: t.varchar().nullable(),
}));
public relations = {
subcomments: this.hasMany(() => TableComment, {
required: true,
primaryKey: 'id',
foreignKey: 'rootId',
}),
};
}
Roman Kushyn commented
Thank you for opening, I'm looking into it, seems to be a bug that's relatively quick to fix
Roman Kushyn commented
I published a fix.
Update orchid-orm
and other related libs if there are any in your package.json and this should work fine now.
Kenji commented
Thanks.