Skip to content

weird unset functionality #2566

Closed
Closed
@bogdandubyk

Description

@bogdandubyk

As far as I can see, laravel-mongodb overrides unset behavior to trigger drop functionality that makes a database query each time you run $moded->unset($field). That means if you have some model that goes through multiple services and making unsets in some of the services for example
In service 1:

$model->unset('blocked');

in service 2:

if ($model->price > 2) {
    $model->unset('margin');
}

in service 3 you are doing an actual save of the model

$model->save();

all this will lead to 3 queries, right? For small projects, it maybe not be an issue, but for big projects, it's a huge overhead for the database. and even worse, it's not a single transaction, and if execution interrupts somewhere it can bring side effects.

I tried to change the behavior of unset to not trigger the drop method but instead just to unset the attribute from the model, but in that case, during the model save, the model does not see changes because isDirty and getDirty methods do not compare with original data to find missing data and does not see changes.

It means you either you killing DB with multiple queries or can't unset the field with eloquent and only set it to null.

Is there any way to fix it???

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions