This message was deleted.
# orm-help
s
This message was deleted.
c
According to : https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#create-1 I need to use person connect. HOWEVER, the documentation doesn't say anything about how to get the value for id. The JSON passed to the API server (listed in the original post), has the PKPersonID, and a RelatedPersonID. I need to connect these to two different people, but can't see a way to pass the value.
Copy code
Prisma.PersonRelationshipCreateInput
doesn't retain that information.
Now getting this error:
Copy code
`ERROR [ExceptionsHandler] Cannot read property 'personOne' of undefined
from the following code:
Copy code
async createPersonRelationship(data: createPersonRelationshipJSON) {
    const PKPersonID = await this.personService.personOne(data.PKPersonID);
personOne defined in person.service.ts
Copy code
personOne(id: any) {
    const personID = this.prisma.person.findUnique({
      where: { 
        PKPersonID: id 
      }
    })
    return personID;
  }
I can't seem to get around the issue of sending a JSON file with the correct fields to create a new record.
trying raw data. Error:
Copy code
[Nest] 99680  - 12/21/2021, 12:48:52 PM   ERROR [ExceptionsHandler] Cannot read property '$executeRawUnsafe' of undefined
TypeError: Cannot read property '$executeRawUnsafe' of undefined
code:
Copy code
async createPersonRelationship(data: createPersonRelationshipJSON) {
    const insert = `
    INSERT INTO [dbo].[PersonRelationship] (
      [ActiveFromDate],
      [ModifiedBy],
      [PKPersonID],
      [RelatedPersonID],
      [RelationshipTypeID],
      [ValidFromDate]
    )
    VALUES (
      ${data.ActiveFromDate},
      ${data.ModifiedBy},
      ${data.PKPersonID},
      ${data.RelatedPersonID},
      ${data.RelationshipTypeID},
      ${data.ValidFromDate},
    );`;

    console.log('\n\n\n' + insert + '\n\n\n');
    const createResponse = this.prisma.$executeRawUnsafe(insert);

    const lastId = this.prisma.$queryRaw`
      SELECT  @@IDENTITY as id;
    `;
    console.log('\n\n\n' + JSON.stringify(data) + '\n\n\n');
    console.log('\n\n\n' + insert + '\n\n\n');
    const [, response] = await this.prisma.$transaction([createResponse, lastId]);
    return this.PersonRelationshipbyID(response?.[0]?.id );
  }
data:
Copy code
INSERT INTO [dbo].[PersonRelationship] (     
   [ActiveFromDate],                          
   [ModifiedBy],                              
   [PKPersonID],                              
   [RelatedPersonID],                         
   [RelationshipTypeID],                      
   [ValidFromDate]                            
 )                                            
 VALUES (                                     
   2021-12-21T00:00:00.000Z,                  
   MDD Admin Tool,                            
   18,                                        
   103,                                       
   1,                                         
   2021-12-21T00:00:00.000Z,                  
 );