Nik
Nik
PPrisma
Created by seromine on 5/6/2024 in #help-and-questions
[Prisma] Nested create with 2 levels of related records
let user = await prisma.user.create({data:{ ... }})
await prisma.post.create({data:{ ..., user_id:user.id }})
let user = await prisma.user.create({data:{ ... }})
await prisma.post.create({data:{ ..., user_id:user.id }})
4 replies
PPrisma
Created by seromine on 5/6/2024 in #help-and-questions
[Prisma] Nested create with 2 levels of related records
model User {
name String
age String
posts Post[]
}

model Post {
body String
uploads String[]

user User @relation(fields: [user_id], references: [id])
user_id String
}
model User {
name String
age String
posts Post[]
}

model Post {
body String
uploads String[]

user User @relation(fields: [user_id], references: [id])
user_id String
}
4 replies
PPrisma
Created by Nik on 4/17/2024 in #help-and-questions
prisma aggregateRaw, how to parse Date back to javascript date, and other special types,
2 replies
PPrisma
Created by Nik on 4/15/2024 in #help-and-questions
@unique on optional field
20 replies
PPrisma
Created by Nik on 4/15/2024 in #help-and-questions
@unique on optional field
No description
20 replies
PPrisma
Created by Nik on 4/15/2024 in #help-and-questions
@unique on optional field
THE SOLUTION What Prisma should be doing is setting Sparse = true on any index of an optional @unique field But I am having to manually remember to do this for every index from an optional @unique If we mark an OPTIONAL field foo @unique, run: db.collection.createIndex( { foo: 1 }, { unique:true, sparse: true } ) If we mark a REQUIRED field foo @unique, run: db.collection.createIndex( { foo: 1 }, { unique:true ) ^ This is all prisma would have to do, currently it runs the second in both cases
20 replies
PPrisma
Created by Nik on 4/15/2024 in #help-and-questions
@unique on optional field
THE PROBLEM OPTIONAL @unique indexes are erroring with duplicate null/undefined values. This means that two records that omit an optionally @unique field will clash
20 replies
PPrisma
Created by Nik on 4/15/2024 in #help-and-questions
@unique on optional field
they're not marked sparse / partial which causes the issue.
20 replies
PPrisma
Created by Nik on 4/15/2024 in #help-and-questions
@unique on optional field
No description
20 replies
PPrisma
Created by Nik on 4/15/2024 in #help-and-questions
@unique on optional field
db.contacts.createIndex(
{ email: 1 },
{ unique: true, partialFilterExpression: { email: { $exists: true } } }
);
db.contacts.createIndex(
{ email: 1 },
{ unique: true, partialFilterExpression: { email: { $exists: true } } }
);
In mongo / mongo drivers I can ignore null values like this.
20 replies
PPrisma
Created by Nik on 4/15/2024 in #help-and-questions
@unique on optional field
yarn prisma db push
...
Error: MongoDB error
Kind: Command failed: Error code 11000 (DuplicateKey): Index build failed: 0008e6a8-ec9a-481b-901a-b4ff6d19ef32: Collection test-next.players ( 4b153292-5b85-4ed1-9f64-8e64be98fda0 ) :: caused by :: E11000 duplicate key error collection: test-next.players index: players_user_id_key dup key: { user_id: null }, labels: {}
0: schema_core::state::SchemaPush
at schema-engine/core/src/state.rs:433
yarn prisma db push
...
Error: MongoDB error
Kind: Command failed: Error code 11000 (DuplicateKey): Index build failed: 0008e6a8-ec9a-481b-901a-b4ff6d19ef32: Collection test-next.players ( 4b153292-5b85-4ed1-9f64-8e64be98fda0 ) :: caused by :: E11000 duplicate key error collection: test-next.players index: players_user_id_key dup key: { user_id: null }, labels: {}
0: schema_core::state::SchemaPush
at schema-engine/core/src/state.rs:433
20 replies
PPrisma
Created by Nik on 4/15/2024 in #help-and-questions
@unique on optional field
20 replies
PPrisma
Created by Nik on 4/15/2024 in #help-and-questions
@unique on optional field
20 replies
PPrisma
Created by Nik on 4/15/2024 in #help-and-questions
@unique on optional field
ty for the help
20 replies
PPrisma
Created by Nik on 4/15/2024 in #help-and-questions
@unique on optional field
am I missing something?
20 replies
PPrisma
Created by Nik on 4/15/2024 in #help-and-questions
@unique on optional field
the issue is that fundamentally the relationship is one to one, and I'd prefer not to hack it with a many-many relationship that isn't accurate
20 replies
PPrisma
Created by Nik on 4/15/2024 in #help-and-questions
@unique on optional field
So a player can be created without a user (witness another player ingame) and a user without a player (hasn't played a game yet)
20 replies
PPrisma
Created by Nik on 4/15/2024 in #help-and-questions
@unique on optional field
So they have to be optional on both sides.
20 replies
PPrisma
Created by Nik on 4/15/2024 in #help-and-questions
@unique on optional field
that's actually not the case here. A user is tied to whether they've signed in. And a player is only linked/created when they start their first game. Both are optional
20 replies
PPrisma
Created by Nik on 4/7/2024 in #help-and-questions
Update nested field in composite types
I understand the type-safety argument but I'd much rather have the option to use a mongoose-type selector with a throw if something goes wrong
3 replies