help with relations

I want the Meal model to kepp track of the absent familyMembers without having to store the data on the familyMember model.
1 Reply
Anas Badran
Anas BadranOP2mo ago
model Meal {
id String @id @default(auto()) @map("_id") @db.ObjectId
date DateTime @default(now())
updatedAt DateTime @updatedAt
type MealTypeEnum
ingredients Dish[] @relation(fields: [ingredientIds], references: [id])
ingredientIds String[] @db.ObjectId
creatorId String @db.ObjectId
creator FamilyMember @relation(name: "MealCreator", fields: [creatorId], references: [id])
familyId String @db.ObjectId
family Family @relation(fields: [familyId], references: [id])
isDeleted Boolean @default(false)
absentMemberIds String[] @db.ObjectId
absentMembers FamilyMember[] @relation("AbsentMembers", fields: [absentMemberIds], references: [id])

@@unique([date, type])
}

model FamilyMember {
id String @id @default(auto()) @map("_id") @db.ObjectId
createdAt DateTime @default(now())
name String
username String @unique
password String
bio String?
dob DateTime?
transactionsCreditor Transaction[] @relation(name: "transaction_creditor")
transactionsDebtor Transaction[] @relation(name: "transaction_debtor")
meals Meal[] @relation(name: "MealCreator")
memberships FamilyMembership[]
createdFamilies Family[]
isDeleted Boolean @default(false)
role RoleEnum @default(USER)
absentMeals Meal[] @relation(name: "AbsentMembers", fields: [absentMealIds], references: [id])
absentMealIds String[] @db.ObjectId
}
model Meal {
id String @id @default(auto()) @map("_id") @db.ObjectId
date DateTime @default(now())
updatedAt DateTime @updatedAt
type MealTypeEnum
ingredients Dish[] @relation(fields: [ingredientIds], references: [id])
ingredientIds String[] @db.ObjectId
creatorId String @db.ObjectId
creator FamilyMember @relation(name: "MealCreator", fields: [creatorId], references: [id])
familyId String @db.ObjectId
family Family @relation(fields: [familyId], references: [id])
isDeleted Boolean @default(false)
absentMemberIds String[] @db.ObjectId
absentMembers FamilyMember[] @relation("AbsentMembers", fields: [absentMemberIds], references: [id])

@@unique([date, type])
}

model FamilyMember {
id String @id @default(auto()) @map("_id") @db.ObjectId
createdAt DateTime @default(now())
name String
username String @unique
password String
bio String?
dob DateTime?
transactionsCreditor Transaction[] @relation(name: "transaction_creditor")
transactionsDebtor Transaction[] @relation(name: "transaction_debtor")
meals Meal[] @relation(name: "MealCreator")
memberships FamilyMembership[]
createdFamilies Family[]
isDeleted Boolean @default(false)
role RoleEnum @default(USER)
absentMeals Meal[] @relation(name: "AbsentMembers", fields: [absentMealIds], references: [id])
absentMealIds String[] @db.ObjectId
}
Want results from more Discord servers?
Add your server