awesome-nest-boilerplate
awesome-nest-boilerplate copied to clipboard
Exception Inserting a new Post
Trying to create a new Post through Swagger I get the following exception:
query: START TRANSACTION
query: INSERT INTO "posts"("id", "created_at", "updated_at", "user_id") VALUES (DEFAULT, DEFAULT, DEFAULT, $1) RETURNING "id", "created_at", "updated_at" -- PARAMETERS: ["fecd4a62-56ae-45da-94b4-97004e39abc3"]
query: INSERT INTO "posts"("id", "created_at", "updated_at", "user_id") VALUES (DEFAULT, DEFAULT, DEFAULT, DEFAULT) RETURNING "id", "created_at", "updated_at"
query failed: INSERT INTO "posts"("id", "created_at", "updated_at", "user_id") VALUES (DEFAULT, DEFAULT, DEFAULT, DEFAULT) RETURNING "id", "created_at", "updated_at"
error: error: null value in column "user_id" of relation "posts" violates not-null constraint
It seems that the line await this.postTranslationRepository.save(translations);
tries to cascade insert the update to the postEntity
without setting the userId
. the second INSERT
in the log gets executed by the postTranslationRepository
Steps to reproduce:
- Start the boilerplate application
- Create a User through Swagger
- Create a Post with 2 translations through Swagger, you'll get the exception in the logs
the same.
Fixed by @nhutcorp, closes #296