This commit is contained in:
@@ -2,6 +2,27 @@ import { defineRelations } from 'drizzle-orm';
|
||||
import * as schema from './schema';
|
||||
|
||||
export const relations = defineRelations(schema, (r) => ({
|
||||
// ── Auth ──────────────────────────────────────
|
||||
user: {
|
||||
sessions: r.many.session(),
|
||||
accounts: r.many.account(),
|
||||
entries: r.many.userEntries(),
|
||||
games: r.many.userGames(),
|
||||
listCompletions: r.many.listItemCompletions()
|
||||
},
|
||||
session: {
|
||||
user: r.one.user({
|
||||
from: r.session.userId,
|
||||
to: r.user.id
|
||||
})
|
||||
},
|
||||
account: {
|
||||
user: r.one.user({
|
||||
from: r.account.userId,
|
||||
to: r.user.id
|
||||
})
|
||||
},
|
||||
|
||||
// ── Progress ──────────────────────────────────
|
||||
tasks: {
|
||||
tasksToTopics: r.many.tasksToTopics()
|
||||
@@ -21,61 +42,41 @@ export const relations = defineRelations(schema, (r) => ({
|
||||
},
|
||||
|
||||
// ── CatchEmAll ────────────────────────────────
|
||||
game: {
|
||||
entries: r.many.pokemonGameEntry()
|
||||
games: {
|
||||
entries: r.many.pokemonGameEntries()
|
||||
},
|
||||
pokemon: {
|
||||
entry: r.many.pokemonGameEntry()
|
||||
entry: r.many.pokemonGameEntries()
|
||||
},
|
||||
pokemonGameEntry: {
|
||||
game: r.one.game({
|
||||
from: r.pokemonGameEntry.gameId,
|
||||
to: r.game.id
|
||||
pokemonGameEntries: {
|
||||
game: r.one.games({
|
||||
from: r.pokemonGameEntries.gameId,
|
||||
to: r.games.id
|
||||
}),
|
||||
pokemon: r.one.pokemon({
|
||||
from: r.pokemonGameEntry.pokemonId,
|
||||
from: r.pokemonGameEntries.pokemonId,
|
||||
to: r.pokemon.id
|
||||
}),
|
||||
userEntries: r.many.userEntry()
|
||||
userEntries: r.many.userEntries()
|
||||
},
|
||||
userEntry: {
|
||||
pokemonGameEntry: r.one.pokemonGameEntry({
|
||||
from: r.userEntry.pokemonGameEntryId,
|
||||
to: r.pokemonGameEntry.id
|
||||
userEntries: {
|
||||
pokemonGameEntry: r.one.pokemonGameEntries({
|
||||
from: r.userEntries.pokemonGameEntryId,
|
||||
to: r.pokemonGameEntries.id
|
||||
}),
|
||||
user: r.one.user({
|
||||
from: r.userEntry.userId,
|
||||
from: r.userEntries.userId,
|
||||
to: r.user.id
|
||||
})
|
||||
},
|
||||
userGame: {
|
||||
userGames: {
|
||||
user: r.one.user({
|
||||
from: r.userGame.userId,
|
||||
from: r.userGames.userId,
|
||||
to: r.user.id
|
||||
}),
|
||||
game: r.one.game({
|
||||
from: r.userGame.gameId,
|
||||
to: r.game.id
|
||||
})
|
||||
},
|
||||
|
||||
// ── Auth ──────────────────────────────────────
|
||||
user: {
|
||||
sessions: r.many.session(),
|
||||
accounts: r.many.account(),
|
||||
entries: r.many.userEntry(),
|
||||
games: r.many.userGame()
|
||||
},
|
||||
session: {
|
||||
user: r.one.user({
|
||||
from: r.session.userId,
|
||||
to: r.user.id
|
||||
})
|
||||
},
|
||||
account: {
|
||||
user: r.one.user({
|
||||
from: r.account.userId,
|
||||
to: r.user.id
|
||||
game: r.one.games({
|
||||
from: r.userGames.gameId,
|
||||
to: r.games.id
|
||||
})
|
||||
},
|
||||
|
||||
@@ -95,5 +96,27 @@ export const relations = defineRelations(schema, (r) => ({
|
||||
from: r.photos.sightingId,
|
||||
to: r.sightings.id
|
||||
})
|
||||
},
|
||||
|
||||
// ── Lists ─────────────────────────────────────
|
||||
lists: {
|
||||
items: r.many.listItems()
|
||||
},
|
||||
listItems: {
|
||||
list: r.one.lists({
|
||||
from: r.listItems.listId,
|
||||
to: r.lists.id
|
||||
}),
|
||||
completions: r.many.listItemCompletions()
|
||||
},
|
||||
listItemCompletions: {
|
||||
item: r.one.listItems({
|
||||
from: r.listItemCompletions.itemId,
|
||||
to: r.listItems.id
|
||||
}),
|
||||
user: r.one.user({
|
||||
from: r.listItemCompletions.userId,
|
||||
to: r.user.id
|
||||
})
|
||||
}
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user