There is not enough information to infer relation

export const historyRelations = relations(histories, ({ many }) => ({
files: many(historyFiles),
}));



const history = await ctx.db.query.histories.findFirst({
where: and(
eq(histories.hospitalId, user.organizationId),
eq(histories.id, input.id)
),
with: {
files: {
where: (files, { eq }) => eq(files.historyId, input.id),
},
},
});
export const historyRelations = relations(histories, ({ many }) => ({
files: many(historyFiles),
}));



const history = await ctx.db.query.histories.findFirst({
where: and(
eq(histories.hospitalId, user.organizationId),
eq(histories.id, input.id)
),
with: {
files: {
where: (files, { eq }) => eq(files.historyId, input.id),
},
},
});
im doing this according to the docs. am i missing something?
2 Replies
carlos
carlosOP16mo ago
got it was missing the relation on the other side
export const historyRelations = relations(histories, ({ many }) => ({
files: many(historyFiles),
}));

export const filesRelations = relations(historyFiles, ({ one }) => ({
history: one(histories, {
fields: [historyFiles.historyId],
references: [histories.id],
}),
}));
export const historyRelations = relations(histories, ({ many }) => ({
files: many(historyFiles),
}));

export const filesRelations = relations(historyFiles, ({ one }) => ({
history: one(histories, {
fields: [historyFiles.historyId],
references: [histories.id],
}),
}));
bmariano
bmariano14mo ago
Thanks man
Want results from more Discord servers?
Add your server