Adding a record to the db where the record is asso...
# orm-help
c
Adding a record to the db where the record is associated with another record. in the schema: Email - is associated with a Person (PKPersonID), which is also the EntityID
Copy code
model Email {
  EmailID        Int       @id @default(autoincrement()) @db.Int
  EntityID?       Int       @db.Int
  EntityTypeID   Int       @db.TinyInt
  EmailAddress   String    @db.VarChar(50)
  EmailTypeID    Int       @db.Int
  Description    String?   @db.VarChar(100)
  Active         Boolean?   @default(false) @db.Bit
  ActiveFromDate DateTime  @db.Date
  ModifiedDate   DateTime?  @default(now()) @db.DateTime
  ModifiedBy     String    @db.VarChar(30)
  ValidFromDate  DateTime?  @db.DateTime2
  ValidToDate    DateTime?  @db.DateTime2
  EmailType      EmailType? @relation(fields: [EmailTypeID], references: [EmailTypeID])

  /// One to many relation with Person Entity through EntityID <-> PKPersonID
  Person      Person? @relation(fields: [EntityID], references: [PKPersonID])
}
Getting data isn't a problem, but when I try and Create a new email for an existing person: JSON sent to API server
Copy code
const tempEmailBody = {
      'EntityID:': PKPersonID,
      'EntityTypeID': 1,
      'EmailAddress': email,
      "ActiveFromDate": this.currentDate,
      "ModifiedDate": this.currentDate,
      "ModifiedBy": "MDD Admin Tool - modified",
      'Active': true
    }
I get an error:
Copy code
Unknown arg `EntityID:` in data.EntityID: for type EmailCreateInput. Did you mean `EntityTypeID`? Available args:
type EmailCreateInput {
  EntityTypeID: Int
  EmailAddress: String
  Description?: String | Null
  Active?: Boolean | Null
  ActiveFromDate: DateTime
  ModifiedDate?: DateTime | Null
  ModifiedBy: String
  ValidFromDate?: DateTime | Null
  ValidToDate?: DateTime | Null
  EmailType?: EmailTypeCreateNestedOneWithoutEmailInput
  Person?: PersonCreateNestedOneWithoutEmailInput
if I try and use Person
Copy code
const tempEmailBody = {
      'Person:': PKPersonID,
      'EntityTypeID': 1,
      'EmailAddress': email,
      "ActiveFromDate": this.currentDate,
      "ModifiedDate": this.currentDate,
      "ModifiedBy": "MDD Admin Tool - modified",
      'Active': true
    }
I get the error:
Copy code
Unknown arg `Person:` in data.Person: for type EmailCreateInput. Did you mean `Person`? Available args:    
type EmailCreateInput {                                                                                    
  EntityTypeID: Int                                                                                        
  EmailAddress: String                                                                                     
  Description?: String | Null                                                                              
  Active?: Boolean | Null                                                                                  
  ActiveFromDate: DateTime                                                                                 
  ModifiedDate?: DateTime | Null                                                                           
  ModifiedBy: String                                                                                       
  ValidFromDate?: DateTime | Null                                                                          
  ValidToDate?: DateTime | Null                                                                            
  EmailType?: EmailTypeCreateNestedOneWithoutEmailInput                                                    
  Person?: PersonCreateNestedOneWithoutEmailInput                                                          
}
IF I try and build something that creates a PersonWhereUniqueInput
Copy code
const tempEmailBody = {
      'Person:': {'PersonWhereUniqueInput': {PKPersonID: this.onePerson.PKPersonID} },
      'EntityTypeID': 1,
      'EmailAddress': email,
      "ActiveFromDate": this.currentDate,
      "ModifiedDate": this.currentDate,
      "ModifiedBy": "MDD Admin Tool - modified",
      'Active': true
    }
I get the error:
Copy code
Unknown arg `Person:` in data.Person: for type EmailCreateInput. Did you mean `Person`? Available args:
type EmailCreateInput {
  EntityTypeID: Int
  EmailAddress: String
  Description?: String | Null
  Active?: Boolean | Null
  ActiveFromDate: DateTime
  ModifiedDate?: DateTime | Null
  ModifiedBy: String
  ValidFromDate?: DateTime | Null
  ValidToDate?: DateTime | Null
  EmailType?: EmailTypeCreateNestedOneWithoutEmailInput
  Person?: PersonCreateNestedOneWithoutEmailInput
}
If I send the following JSON (notice, no EntityID or anyway to identify to which Person the Email belongs)
Copy code
{
  "EntityTypeID": 1,
  "EmailAddress": "<mailto:bbarker@allenmatkins.com|bbarker@allenmatkins.com>",
  "ActiveFromDate": "2022-03-15T00:00:00.000Z",
  "ModifiedDate": "2022-03-15T00:00:00.000Z",
  "ModifiedBy": "MDD Admin Tool - modified",
  "Active": true
}
I get THIS error:
Copy code
Invalid `this.prisma.email.create()` invocation in
C:\Sites\AM-API-MDD\src\app\email\email.service.ts:59:30

   56 }
   57
   58 async createEmail(data: Prisma.EmailCreateInput) {
→  59   return this.prisma.email.create(
  Null constraint violation on the fields: (`EntityID`)
I understand why it complains when there is no EntityID, but I don't understand why I get an error when I do send one: Unknown arg 'EntityID:' in data.EntityID:
j
Are those
:
in your object key names intentional?
Should
Copy code
const tempEmailBody = {
      'EntityID:': PKPersonID,
               ^
      'EntityTypeID': 1,
maybe be
Copy code
const tempEmailBody = {
      'EntityID': PKPersonID,
      'EntityTypeID': 1,