Error using relational queries but not with core queries

when i do
const invitesData = await db.select().from(invites).innerJoin(members, eq(invites.inviterId, members.id)).where(eq(invites.invitedId, user.id));
const invitesData = await db.select().from(invites).innerJoin(members, eq(invites.inviterId, members.id)).where(eq(invites.invitedId, user.id));
everything works as intended, but when I do
const invitesData = await db.query.invites.findMany({
with: {
inviter: true
},
where: eq(invites.invitedId, user.id),
})
const invitesData = await db.query.invites.findMany({
with: {
inviter: true
},
where: eq(invites.invitedId, user.id),
})
it gives me: PostgresError: column "invites.created_at" must appear in the GROUP BY clause or be used in an aggregate function relationships:
export const usersRelations = relations(users, ({many}) => ({
members: many(members),
invites: many(invites),
}))

export const invitesRelations = relations(invites, ({one}) => ({
inviter: one(members, {
fields: [invites.inviterId],
references: [members.id],
}),
invited: one(users, {
fields: [invites.invitedId],
references: [users.id],
})
}))

export const membersRelations = relations(members, ({many, one}) => ({
invites: many(invites),
}))
export const usersRelations = relations(users, ({many}) => ({
members: many(members),
invites: many(invites),
}))

export const invitesRelations = relations(invites, ({one}) => ({
inviter: one(members, {
fields: [invites.inviterId],
references: [members.id],
}),
invited: one(users, {
fields: [invites.invitedId],
references: [users.id],
})
}))

export const membersRelations = relations(members, ({many, one}) => ({
invites: many(invites),
}))
Thank you in advance <3
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server