I can't update, create or delete from a table in t...
# orm-help
c
I can't update, create or delete from a table in the database. Undefined errors error:
Copy code
ERROR [ExceptionsHandler] Cannot read property '$executeRawUnsafe' of undefined
code:
Copy code
async deletePersonRelationship(where: Prisma.PersonRelationshipWhereUniqueInput) {
    const insert = `DELETE FROM [dbo].[PersonRelationship] WHERE PersonRelationshipID=${where.PersonRelationshipID};`;
    return this.prisma.$executeRawUnsafe(insert);
//  return this.prisma.$executeRaw`DELETE FROM [dbo].[PersonRelationship] WHERE PersonRelationshipID=${where.PersonRelationshipID};`;
//  the above line doesn't work either
  }
where:
Copy code
{ PersonRelationshipID: 359 }
If I run the script on the SQL server, it works. Similar issue with Update and Create. With Update I tried using the internal Prisma commands:
Copy code
async updatePersonRelationship(params: {
    where: Prisma.PersonRelationshipWhereUniqueInput;
    data: Prisma.PersonRelationshipUpdateInput;
  }) {
    const { data, where } = params;
    const response = await this.prisma.personRelationship.update({
      data,
      where,
    });
  }
but I get the following error:
Copy code
ERROR [ExceptionsHandler] Cannot read property 'personRelationship' of undefined
If I switch to the following code:
Copy code
async updatePersonRelationship(params: {
    where: Prisma.PersonRelationshipWhereUniqueInput;
    data: Prisma.PersonRelationshipUpdateInput;
  }) {
    const { data, where } = params;
    console.log('\n\n\n' + JSON.stringify(data) + '\n\n\n');
    // const response = await this.prisma.personRelationship.update({
    //   data,
    //   where,
    // });
    // console.log(response);

    const insert = `UPDATE [dbo].[PersonRelationship] 
                    SET ActiveFromDate=$data.ActiveFromDate,
                        ModifiedBy=$ModifiedBy,
                        PKPersonID=$PKPersonID,
                        RelatedPersonID=$RelatedPersonID,
                        RelationshipTypeID=$RelationshipTypeID
                    WHERE PersonRelationshipID=$where`;
    return this.prisma.$executeRawUnsafe(insert);
  }
I get the following error:
Copy code
{"ActiveFromDate":"2021-12-21T00:00:00.000Z","ModifiedBy":"MDD Admin Tool","PKPersonID":18,"RelatedPerson":285,"RelationshipTypeID":1}
[Nest] 102196  - 12/21/2021, 2:22:32 PM   ERROR [ExceptionsHandler] Cannot read property '$executeRawUnsafe' of undefined
I included the console log of the data to show what was passed. Again, this script works on the sql server. I am at a loss as to why I'm getting undefined errors.