-
Notifications
You must be signed in to change notification settings - Fork 45
Open
Description
Hi,
I've built a crud app with mootensai/yii2-enhanced-gii, there are related tables by foreign keys (n:1, n:m).
In the case I got an validation error, after pressing update a second time the app throw the following error:
`Stale Object Exception – yii\db\StaleObjectException
The object being updated is outdated.
1. in /home/none/work/rebase/vendor/yiisoft/yii2/db/BaseActiveRecord.php at line 813
804805806807808809810811812813814815816817818819820821822
if ($lock !== null) {
$values[$lock] = $this->$lock + 1;
$condition[$lock] = $this->$lock;
}
// We do not check the return value of updateAll() because it's possible
// that the UPDATE statement doesn't change anything and thus returns 0.
$rows = static::updateAll($values, $condition);
if ($lock !== null && !$rows) {
throw new StaleObjectException('The object being updated is outdated.');
}
if (isset($values[$lock])) {
$this->$lock = $values[$lock];
}
$changedAttributes = [];
foreach ($values as $name => $value) {
$changedAttributes[$name] = isset($this->_oldAttributes[$name]) ? $this->_oldAttributes[$name] : null;
2. in /home/none/work/rebase/vendor/yiisoft/yii2/db/ActiveRecord.php at line 631 – yii\db\BaseActiveRecord::updateInternal(null)
3. in /home/none/work/rebase/vendor/yiisoft/yii2/db/BaseActiveRecord.php at line 681 – yii\db\ActiveRecord::update(true, null)
4. in /home/none/work/rebase/vendor/mootensai/yii2-relation-trait/RelationTrait.php at line 166 – yii\db\BaseActiveRecord::save()
160161162163164165166167168169170171172
/* @var $this ActiveRecord */
$db = $this->getDb();
$trans = $db->beginTransaction();
$isNewRecord = $this->isNewRecord;
$isSoftDelete = isset($this->_rt_softdelete);
try {
if ($this->save()) {
$error = false;
if (!empty($this->relatedRecords)) {
/* @var $records ActiveRecord | ActiveRecord[] */
foreach ($this->relatedRecords as $name => $records) {
if (in_array($name, $skippedRelations))
continue;
5. in /home/none/work/rebase/controllers/SalesLeadController.php at line 145 – app\models\base\SalesLead::saveAll()
`
anybody an idea what's the problem?
Cheers!
Metadata
Metadata
Assignees
Labels
No labels