Thursday, November 14, 2024
HomeGolang Updating report with its associations - Getting Assist

[GORM] Updating report with its associations – Getting Assist


Whats up Gophers.

That is my entity:

sort DishEntity struct {
	gorm.Mannequin
	Date        time.Time
	Substances []MeasuredIngredientEntity `gorm:"many2many:dish_measuredingredient;"`
}

That is my replace operate:

func UpdateDish(db *gorm.DB, d entities.DishEntity) error {
	if err := db.Updates(&d).Error; err != nil {
		return err
	}
	return nil
}

Right here is my downside:

Once I add new ingredient to the dish it really works as anticipated however after I take away one thing the change isn’t mirrored within the database.

I do know this isn’t how I suppose to do it however which technique ought to I select then ?

GPT gave me a number of options however all of them had some bugs and surprising behaviors.

Have you ever tried with Change?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments