laravel sava encountered problems saving data
1 the database is divided into tables by date, for example: day_01,day_02.
2 when updating the data, query a piece of data in the day_01 table according to the conditions as follows:
$objData = $objModel->setTable("day_01")->where(["user_id"=>123])->first();
3 when updating data
//:setTable day_01 day_021(set day_02user_id=123)
$intNum = $objData->num;
$objData->setTable("day_02");$objData->num = $intNum+20; $isRs = $objData->save();
dd($isRs);//1
4$isRs at this time, this returns 1. According to reason, it should be 0 to use listeners to listen to sql print execution of sql is also wrong. Why will it return 1
?after several days of research
sql
select * from day_01 where user_id=123;//
update day_02 set num=30 where user_id=123;//
vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php
606(laravel5.5) performUpdate()
628 $this->setKeysForSaveQuery($query)->update($dirty);
0 laravel true
-sharp
protected function performUpdate(Builder $query)
{
// If the updating event returns false, we will cancel the update operation so
// developers can hook Validation systems into their models and cancel this
// operation if the model does not pass validation. Otherwise, we update.
if ($this->fireModelEvent("updating") === false) {
return false;
}
// First we need to create a fresh query instance and touch the creation and
// update timestamp on the model which are maintained by us for developer
// convenience. Then we will just continue saving the model instances.
if ($this->usesTimestamps()) {
$this->updateTimestamps();
}
// Once we have run the update operation, we will fire the "updated" event for
// this model instance. This will allow developers to hook into these after
// models are updated, giving them a chance to do any special processing.
$dirty = $this->getDirty();
if (count($dirty) > 0) {
$this->setKeysForSaveQuery($query)->update($dirty);
$this->fireModelEvent("updated", false);
$this->syncChanges();
}
return true;
}