Benjacho / belongs-to-many-field-nova

Belongs To Many field Laravel nova to represent many to many relationship in field.
MIT License
157 stars 81 forks source link

attaching values to every other saved object in boot() #60

Closed hatja closed 4 years ago

hatja commented 4 years ago

When i try to update other objects in the boot() of the model, the package attaches the values to all the other objects that was updated too. What i mean

protected static function boot()
{
    parent::boot();
    static::creating(function($newModel) {
       $someOtherObject = self::where('something', $newModel->something)->first();
       $someOtherObject->update(['something' => 'something-else']);
    });
}

in this case, the selected values will be attached to $someOtherObject too, not only to the newly created one.

hatja commented 4 years ago

Turned out its coz of the package uses $model::saved() for attaching, so it will apply for all the other object that were updated.

I ended up with raw SQL statement for the update, so they wont trigger the saved event.