fix relations

This commit is contained in:
Anika Raemer 2025-10-10 19:41:34 +02:00
parent 58ef7fbc00
commit 0587153829
8 changed files with 64 additions and 79 deletions

View file

@ -43,8 +43,10 @@ export class RecipeDtoEntityMapper extends AbstractDtoEntityMapper<RecipeEntity,
entity.instructionSteps = dto.instructions.map((stepDto) => {
const stepEntity = this.instructionStepMapper.toEntity(stepDto);
// Always set the relation
stepEntity.recipe = entity;
// Set the relation if the entity already exists in DB
if(entity.hasValidId()){
stepEntity.recipe = entity;
}
// If it's a new step (no id from client), let DB generate a new UUID
if (!stepDto.id) {
@ -57,7 +59,11 @@ export class RecipeDtoEntityMapper extends AbstractDtoEntityMapper<RecipeEntity,
// map ingredient groups
entity.ingredientGroups = dto.ingredientGroups.map((groupDto) => {
const groupEntity = this.ingredientGroupMapper.toEntity(groupDto);
groupEntity.recipe = entity;
// Set the relation if the entity already exists in DB
if(entity.hasValidId()){
groupEntity.recipe = entity;
}
// If it's a new group (no id from client), let DB generate a new UUID
if (!groupDto.id) {
delete (groupEntity as any).id;
}