Martin Pinnau
05/12/2022, 11:35 AMtype EmailMessage { .... error: Model declarations have to be indicated with the `model` keyword`
same error also for EmailSubject
my schema:
model Email {
id String @id @map("_id") @db.ObjectId
name String @unique
emailMessage EmailMessage
emailSubject EmailSubject
receiverGroup Receiver[]
isActivated Boolean @default(value: true)
role String
btnName String
}
type EmailMessage {
id String
messageDe String
messageEn String
}
type EmailSubject {
id String
subjectDe String
subjectEn String
}
type Receiver {
id String
email String
firstName String
lastName String
}
What am I doing wrong regarding these embedded documents ?
Is there support for embedded document lists but not for embedded documents ?Nurul
05/12/2022, 12:30 PMgenerator client {
provider = "prisma-client-js"
binaryTargets = ["native"]
}
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
model Email {
id String @id @default(auto()) @map("_id") @db.ObjectId
name String @unique
emailMessage EmailMessage
emailSubject EmailSubject
receiverGroup Receiver[]
isActivated Boolean @default(value: true)
role String
btnName String
}
type EmailMessage {
id String
messageDe String
messageEn String
}
type EmailSubject {
id String
subjectDe String
subjectEn String
}
type Receiver {
id String
email String
firstName String
lastName String
}
Query
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
async function main() {
const response = await prisma.email.create({
data: {
btnName: "btnName",
emailMessage: {
id: "1",
messageDe: "messageDe",
messageEn: "messageEn",
},
emailSubject: {
id: "1",
subjectDe: "subjectDe",
subjectEn: "subjectEn",
},
name: "name",
role: "role",
isActivated: true,
receiverGroup: {
id: "1",
email: "<mailto:email@email.com|email@email.com>",
firstName: "firstName",
lastName: "lastName",
},
},
});
console.log(response);
}
main()
.catch((e) => {
throw e;
})
.finally(async () => {
await prisma.$disconnect();
});
Response:
{
emailMessage: { id: '1', messageDe: 'messageDe', messageEn: 'messageEn' },
emailSubject: { id: '1', subjectDe: 'subjectDe', subjectEn: 'subjectEn' },
receiverGroup: [
{
id: '1',
email: '<mailto:email@email.com|email@email.com>',
firstName: 'firstName',
lastName: 'lastName'
}
],
id: '627cfd4cb10b4047615b03f7',
name: 'name',
isActivated: true,
role: 'role',
btnName: 'btnName'
}Nurul
05/12/2022, 12:30 PMNurul
05/12/2022, 12:31 PM@default(auto()) in Email model in id fieldMartin Pinnau
05/12/2022, 12:40 PMimport { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
async function main() {
await prisma.$connect()
const emails = await prisma.email.findMany()
console.log(emails)
}
main()
.catch(console.error)
.finally(() => prisma.$disconnect())Martin Pinnau
05/12/2022, 12:43 PMtype Email @db(name: "emails") {...
Threw errors in P3.14 when I tried thatNurul
05/12/2022, 1:05 PMmodel in schema file, type keyword is reserved for embedded document and shouldn't be used for defining collection.Martin Pinnau
05/12/2022, 1:23 PMmodel Email @db(name: "emails") {...
using a custom name for the collection ?Martin Pinnau
05/12/2022, 1:35 PMMartin Pinnau
05/12/2022, 1:42 PMdatasource db {
provider = "mongodb"
url = env("DATABASE_URL")
collection = "emails"
}
would be niceNurul
05/12/2022, 1:45 PMmodel Email {
@@map("emails")
}Nurul
05/12/2022, 1:45 PMMartin Pinnau
05/12/2022, 2:12 PMNurul
05/12/2022, 2:40 PMMartin Pinnau
05/12/2022, 2:53 PMnexus-plugin-prisma@0.35.0" has incorrect peer dependency "@prisma/client@2.23.x"
When I pin the prisma client to 2.23.0 I get these model declaration errors.
Do you have any idea how I could resolve this ? I really need nexus-plugin-prisma.Nurul
05/12/2022, 3:03 PMMartin Pinnau
05/12/2022, 3:32 PMMartin Pinnau
05/12/2022, 3:33 PMconst emails = await prisma.email.findMany()
Error converting field "id" of expected non-nullable type "String", found incompatible value of "null".
is this a bug ? normally findMany() should just return all entries...Martin Pinnau
05/12/2022, 3:37 PMprisma.email.findMany({ select: { id: true } })
which returns
[
{ id: '62399af4054ec80008386eee' },
{ id: '62399af4054ec80008386ef6' },
{ id: '62399af4054ec80008386eec' },
{ id: '62399af4054ec80008386eff' },
{ id: '62399af4054ec80008386f00' },
{ id: '62399af4054ec80008386f05' },
{ id: '62399af4054ec80008386f08' },
{ id: '62399af4054ec80008386f0b' },
{ id: '62399af4054ec80008386ef1' },
{ id: '62399af4054ec80008386efb' },
{ id: '62399af4054ec80008386f0e' },
{ id: '62399af4054ec80008386f11' },
{ id: '62399af4054ec80008386f16' },
{ id: '62399af4054ec80008386f14' },
{ id: '62399af4054ec80008386f15' },
{ id: '62399af4054ec80008386ef4' },
{ id: '626fe6e10b5bca0008210a5b' },
{ id: '626fe6e10b5bca0008210a5e' },
{ id: '626fe6e10b5bca0008210a61' }
]Nurul
05/13/2022, 8:32 AMMartin Pinnau
05/13/2022, 8:50 AMMartin Pinnau
05/13/2022, 8:53 AMMartin Pinnau
05/13/2022, 8:53 AMMartin Pinnau
05/13/2022, 9:37 AMmeta: { field: 'id', expected_type: 'String', found: 'null' }Martin Pinnau
05/13/2022, 9:39 AMMartin Pinnau
05/13/2022, 9:40 AMdb.emails.find({_id: null})
.limit(100)
-> No records foundNurul
05/13/2022, 11:22 AMconst emails = await prisma.email.findMany()
It should return all the emails.
Can you create a Bug Report for it here.
I think if you add all the fields in select clause then it will work for now.Martin Pinnau
05/13/2022, 11:29 AMMartin Pinnau
05/13/2022, 11:36 AMconst emails = await prisma.email.findMany({
select: {
id: true,
name: true,
isActivated: true,
role: true,
btnName: true,
},
});
works, but
const emails = await prisma.email.findMany({
select: {
id: true,
name: true,
emailMessage: true,
isActivated: true,
role: true,
btnName: true,
},
});
does not! ;)Nurul
05/13/2022, 11:37 AMMartin Pinnau
05/13/2022, 11:37 AMNurul
05/13/2022, 11:37 AMMartin Pinnau
05/13/2022, 11:37 AMMartin Pinnau
05/13/2022, 11:38 AMError converting field "id" of expected non-nullable type "String", found incompatible value of "null"
code: 'P2032',
clientVersion: '3.14.0',
meta: { field: 'id', expected_type: 'String', found: 'null' }Martin Pinnau
05/13/2022, 11:42 AM@id @map("_id") @db.ObjectId
to the id String field in the nested type, but that doesn't work, I thought maybe the id field has to be defined like in the main model, but this doesn't seem to be the caseMartin Pinnau
05/13/2022, 11:56 AM@map("_id"):
type EmailMessage {
id String @map("_id")
messageDe String
messageEn String
}
type EmailSubject {
id String @map("_id")
subjectDe String
subjectEn String
}
type Receiver {
id String @map("_id")
email String
firstName String
lastName String
}Martin Pinnau
05/13/2022, 11:56 AMMartin Pinnau
05/13/2022, 11:58 AMMartin Pinnau
05/13/2022, 12:00 PM@db.ObjectId is neccessary, it also worksNurul
05/13/2022, 12:03 PMconst emails = await prisma.email.findMany()Martin Pinnau
05/13/2022, 12:04 PMMartin Pinnau
05/13/2022, 12:04 PMMartin Pinnau
05/13/2022, 12:05 PM@map("_id")Nurul
05/13/2022, 12:05 PMMartin Pinnau
05/13/2022, 12:05 PM