TS2353: Object literal may only specify known properties, and where does not exist in type

Hello everyone! I have an error when trying to create a nested filter.
export const user = pgTable('users', {
id: uuid('id')
.primaryKey()
.default(sql`gen_random_uuid()`),
firstName: varchar('first_name', { length: 225 }),
lastName: varchar('last_name', { length: 225 }),
birthday: date('birthday'),
email: varchar('email', { length: 225 }).notNull().unique(),
...timestamps,
});

export const userCode = pgTable(
'user_code',
{
userId: uuid('user_id')
.references(() => user.id)
.notNull(),
value: numeric('value').notNull(),
createdAt: timestamps.createdAt,
},
() => ({
indexes: [
{
name: 'user_code_composite_idx',
columns: ['userId', 'value'],
},
],
}),
);
export const user = pgTable('users', {
id: uuid('id')
.primaryKey()
.default(sql`gen_random_uuid()`),
firstName: varchar('first_name', { length: 225 }),
lastName: varchar('last_name', { length: 225 }),
birthday: date('birthday'),
email: varchar('email', { length: 225 }).notNull().unique(),
...timestamps,
});

export const userCode = pgTable(
'user_code',
{
userId: uuid('user_id')
.references(() => user.id)
.notNull(),
value: numeric('value').notNull(),
createdAt: timestamps.createdAt,
},
() => ({
indexes: [
{
name: 'user_code_composite_idx',
columns: ['userId', 'value'],
},
],
}),
);
export const userRelations = relations(user, ({ many, one }) => ({
refreshTokens: many(refreshToken),
code: one(userCode, {
fields: [user.id],
references: [userCode.userId],
}),
}));

export const userCodeRelations = relations(userCode, ({ one }) => ({
user: one(user, {
fields: [userCode.userId],
references: [user.id],
}),
}));
export const userRelations = relations(user, ({ many, one }) => ({
refreshTokens: many(refreshToken),
code: one(userCode, {
fields: [user.id],
references: [userCode.userId],
}),
}));

export const userCodeRelations = relations(userCode, ({ one }) => ({
user: one(user, {
fields: [userCode.userId],
references: [user.id],
}),
}));
const user = await tx.query.userCode.findFirst({
where: eq(schema.userCode.value, code),
columns: {
value: true,
},
with: {
user: {
where: (user, { eq }) => eq(user.email, userEmail),
columns: {
id: true,
},
},
},
});
const user = await tx.query.userCode.findFirst({
where: eq(schema.userCode.value, code),
columns: {
value: true,
},
with: {
user: {
where: (user, { eq }) => eq(user.email, userEmail),
columns: {
id: true,
},
},
},
});
What could be the problem? "drizzle-orm": "^0.36.4", node -v - 20
No description
19 Replies
Xpecial Poo
Xpecial Pooā€¢4w ago
i have literally the same issue. Already posted here but nobody could help
chepracio
chepracioOPā€¢4w ago
I use @ts-ignore, bot i lost correct types((( @moderator who can help me? @Angelelz I noticed you often respond to messages; maybe you could help?
Darren
Darrenā€¢4w ago
@chepracio can you try change with: {user to with : {users actually totally forgot, you cant use nested wheres currently i dont think
Angelelz
Angelelzā€¢4w ago
I think that you are not allowed to use where in a one relation
chepracio
chepracioOPā€¢4w ago
Iā€™m doing everything according to the documentation, it works, the issue is only with the types. https://orm.drizzle.team/docs/rqb#select-filters
Drizzle ORM - Query
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
No description
Angelelz
Angelelzā€¢4w ago
In the docs example, one post has many comments. However in you code, the userCode has one user. That's why drizzle is trying to alert you via types The nested where can only filter the user, with the current version of relational queries, you can't filter userCode, which is probably what you intent to do.
chepracio
chepracioOPā€¢4w ago
I understand you, I'll check how it will work with one to many
chepracio
chepracioOPā€¢3w ago
I still believe your typing implementation is incorrect. I want to update a field that can be null, but I get an error in the set method when trying to assign a value to the field. This is incorrect, as the field can be absent, but it should still be assignable.
No description
No description
No description
No description
chepracio
chepracioOPā€¢3w ago
@Angelelz Hello! Can you tell me if this is a problem or if I am using ORM incorrectly?
Darren
Darrenā€¢3w ago
put an example in drizzle run
Angelelz
Angelelzā€¢3w ago
This
chepracio
chepracioOPā€¢3w ago
šŸ˜© šŸ¤·ā€ā™‚ļø Sorry, I don't understood you @Darren What do you mean? You don't see the images?
Darren
Darrenā€¢3w ago
Yes, of course I see the images, but I'm unable to replicate this behaviour, whether a uuid is defined as not null or not it always shows up in a set operation. So the idea is to go to drizzle.run and recreate the behaviour you see using your code so we can see it happening. And if you can't replicate it then you know it's an issue in your files, probably a rogue import statement of a schema or something.
chepracio
chepracioOPā€¢3w ago
What is drizzle.run?
chepracio
chepracioOPā€¢3w ago
https://drizzle.run/wex9jx8o6y419osjgjk5e5qp There is no error here, but there is one in the code. TypeScript complains about it.
No description
Angelelz
Angelelzā€¢3w ago
You might have a setup problem with typescript. Make sure you use "strict": true in your tsconfig.json
chepracio
chepracioOPā€¢2w ago
I use it
No description
chepracio
chepracioOPā€¢2w ago
@Darren Did you watch?
Want results from more Discord servers?
Add your server