Multiple relations

Let's say I have this relationship from message to users:
export const MessageRelations = relations(MessageTable, ({ one }) => ({
  sender: one(UserTable, {
    fields: [MessageTable.sender_id],
    references: [UserTable.id],
  }),

  recipient: one(UserTable, {
    fields: [MessageTable.recipient_id],
    references: [UserTable.id],
  }),
}))

And I'd like to add a relation from user to messages, by the sender. I thought of doing this:
export const UserRelations = relations(UserTable, ({ many }) => ({
  messages: many(MessageTable),
}))

But it errors out, Error: There is not enough information to infer relation "UserTable.messages"
I assume I need to tell it what relation messages is linked with, but how do I go about doing that? The docs provide no information about this.
Was this page helpful?