troelskn / laravel-fillable-relations

Provides HasFillableRelations trait to Eloquent models
64 stars 23 forks source link

BEWARE!!! DON'T USE WITHOUT READING THIS FIRST!!! #20

Closed zanozik closed 4 years ago

zanozik commented 4 years ago

The package is deceitful!

If you will make a new model and fill relationships, the package will automatically persist all of that in your database!!!

//HasFillableRelations.php:139

if (!$this->exists) {
    $this->save();
    $relation = $this->{camel_case($relationName)}();
 }
.....
$relation->save($related);
SteveEdson commented 3 years ago

Just ran into this issue, trying to create a model like so:

$product = $shop->products()->create($request->input());

Where Product uses HasFillableRelations, and Shop has a HasMany relationship on products, results in the error:

General error: 1364 Field 'shop_id' doesn't have a default value (SQL: insert into `products`....

It just creates and saves the model without taking into account the parent relationship. Unfortunately I think I will have to stop using the package because of this.