To sorry my poor English.
I using Laravel framework in my project and once change the new record
$product = new Product();
$product->fill($attributes)->save();
to
$product = new Product();
$product->update($attributes);
and a big problem did.
All rows of products table updated.
This is my wrong way to make the problem, but the Model@update() to updating all table when new record is dangerous.
I think Model@update() non-exists record should goes create or raise exceptions better.
I'm pretty sure the current behavior won't be changed...
The method specifically checks if the model does not exist and then runs the update of the whole table. So it is definitely intended:
public function update(array $attributes = array())
{
if ( ! $this->exists)
{
return $this->newQuery()->update($attributes);
}
return $this->fill($attributes)->save();
}
You are also able to call any query builder method on a model and it will run against the respective table.
That so sad, I knew the Rails update() method just alias of assign attributes and save (that would be create if record not exists).
The update() method keep literal means, but you made the hidden problem in Laravel.
I'll just notice my team _don't use update() method directly_.
Feel free to override the update method in a base model in your project.
Yes, I can override it, but it is hack, my point is implicit result of update method in Laravel framework.
It's not a hack. It's just a way to change the behavior of the method for your project(s) because I'm pretty sure that this won't be changed in the framework itself...
OK, what's the purpose of update method to updating all table? To punch the gay if he make mistake?
The update is the Model level method, if you wants to update all records, you needs find and update them, or make DB::table('users')->update(['status' => xxx]) instead.
I think the update method make two different things is bad,
If we need this feature, we need implement some like updateColumns method (Ralis way) to do it.
Most helpful comment
I'm pretty sure the current behavior won't be changed...
The method specifically checks if the model does not exist and then runs the update of the whole table. So it is definitely intended:
You are also able to call any query builder method on a model and it will run against the respective table.