db.query not updating

Hey all! I recently refactored my schema to take advantage of the findMany and findFirst functions. These are my collectionsTable relations:
export const collectionsRelations = relations(collectionsTable, ({ one }) => ({
author: one(usersTable, {
fields: [collectionsTable.authorID],
references: [usersTable.id],
}),
}))
export const collectionsRelations = relations(collectionsTable, ({ one }) => ({
author: one(usersTable, {
fields: [collectionsTable.authorID],
references: [usersTable.id],
}),
}))
and a collection references those tables like so in the table setup:
authorID: varchar({ length: 255 })
.notNull()
.references(() => usersTable.id),
authorID: varchar({ length: 255 })
.notNull()
.references(() => usersTable.id),
and my query looks like this:
const collectionsQuery = await db.query.collectionsTable.findMany({
where: userID
? or(
eq(collectionsTable.publicationStatus, PubStatus.PUBLIC), // Public collections
and(
eq(collectionsTable.authorID, userID), // User-created collections
eq(collectionsTable.publicationStatus, PubStatus.DRAFT)
),
and(
eq(teamUsersTable.userID, userID), // Team-only collections
eq(collectionsTable.publicationStatus, PubStatus.TEAM_ONLY)
)
)
: eq(collectionsTable.publicationStatus, PubStatus.PUBLIC), // Only public collections

})
const collectionsQuery = await db.query.collectionsTable.findMany({
where: userID
? or(
eq(collectionsTable.publicationStatus, PubStatus.PUBLIC), // Public collections
and(
eq(collectionsTable.authorID, userID), // User-created collections
eq(collectionsTable.publicationStatus, PubStatus.DRAFT)
),
and(
eq(teamUsersTable.userID, userID), // Team-only collections
eq(collectionsTable.publicationStatus, PubStatus.TEAM_ONLY)
)
)
: eq(collectionsTable.publicationStatus, PubStatus.PUBLIC), // Only public collections

})
But I keep getting the error:
Unknown column 'collectionsTable.userID' in 'where clause'
Unknown column 'collectionsTable.userID' in 'where clause'
even though I'm only looking for collectionsTable.authorID. Does drizzle have a cache I need to refresh? I was using collectionsTable.userID before but renamed the column. I've ran drizzle-kit push and there is nothing to change. Thanks in advance for any help as this query was working as a select with join tables before. Wondering if I should just revert...
1 Reply
TOSL
TOSL3w ago
Try using a callback

Did you find this page helpful?