import { defineRelations } from "drizzle-orm"; import { actors, sessions } from "./actors"; import { tickets, ticketParticipants, ticketMessages, ticketAttachments } from "./tickets"; export const schemaRelations = defineRelations( { actors, sessions, tickets, ticketParticipants, ticketMessages, ticketAttachments, }, (r) => ({ actors: { sessions: r.many.sessions({ from: r.actors.id, to: r.sessions.userId, }), openedTickets: r.many.tickets({ from: r.actors.id, to: r.tickets.openedBy, alias: "ticket_opened_by", }), subjectTickets: r.many.tickets({ from: r.actors.id, to: r.tickets.subject, alias: "ticket_subject", }), claimedTickets: r.many.tickets({ from: r.actors.id, to: r.tickets.claimedBy, alias: "ticket_claimed_by", }), ticketParticipants: r.many.ticketParticipants({ from: r.actors.id, to: r.ticketParticipants.actorId, }), ticketMessages: r.many.ticketMessages({ from: r.actors.id, to: r.ticketMessages.actorId, }), ticketAttachments: r.many.ticketAttachments({ from: r.actors.id, to: r.ticketAttachments.actorId, }), }, sessions: { actor: r.one.actors({ from: r.sessions.userId, to: r.actors.id, }), }, tickets: { opener: r.one.actors({ from: r.tickets.openedBy, to: r.actors.id, alias: "ticket_opened_by", }), subjectActor: r.one.actors({ from: r.tickets.subject, to: r.actors.id, alias: "ticket_subject", }), claimedByActor: r.one.actors({ from: r.tickets.claimedBy, to: r.actors.id, alias: "ticket_claimed_by", }), participants: r.many.ticketParticipants({ from: r.tickets.id, to: r.ticketParticipants.ticketId, }), messages: r.many.ticketMessages({ from: r.tickets.id, to: r.ticketMessages.ticketId, }), attachments: r.many.ticketAttachments({ from: r.tickets.id, to: r.ticketAttachments.ticketId, }), }, ticketParticipants: { tickets: r.one.tickets({ from: r.ticketParticipants.ticketId, to: r.tickets.id, }), actor: r.one.actors({ from: r.ticketParticipants.actorId, to: r.actors.id, }), }, ticketMessages: { tickets: r.one.tickets({ from: r.ticketMessages.ticketId, to: r.tickets.id, }), actor: r.one.actors({ from: r.ticketMessages.actorId, to: r.actors.id, }), attachments: r.many.ticketAttachments({ from: r.ticketMessages.id, to: r.ticketAttachments.messageId, }), }, ticketAttachments: { tickets: r.one.tickets({ from: r.ticketAttachments.ticketId, to: r.tickets.id, }), actor: r.one.actors({ from: r.ticketAttachments.actorId, to: r.actors.id, }), message: r.one.ticketMessages({ from: r.ticketAttachments.messageId, to: r.ticketMessages.id, }), }, }), );