pkgs/db/src/schemas/relations.ts (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
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,
}),
},
}),
);
|