docs/guide/db-active-record.md fix (#16704) [skip ci]

This commit is contained in:
Nobuo Kihara
2018-09-13 08:18:27 +09:00
committed by Alexander Makarov
parent 20899a5aa9
commit e2eee94108

View File

@ -744,8 +744,8 @@ To use optimistic locking,
The column should be of big integer type (in MySQL it would be `BIGINT DEFAULT 0`). The column should be of big integer type (in MySQL it would be `BIGINT DEFAULT 0`).
2. Override the [[yii\db\ActiveRecord::optimisticLock()]] method to return the name of this column. 2. Override the [[yii\db\ActiveRecord::optimisticLock()]] method to return the name of this column.
3. Implement [[\yii\behaviors\OptimisticLockBehavior|OptimisticLockBehavior]] inside your model class to automatically parse its value from received requests. 3. Implement [[\yii\behaviors\OptimisticLockBehavior|OptimisticLockBehavior]] inside your model class to automatically parse its value from received requests.
4. In the Web form that takes user inputs, add a hidden field to store the current version number of the row being updated.
Remove the version attribute from validation rules as [[\yii\behaviors\OptimisticLockBehavior|OptimisticLockBehavior]] should handle it. Remove the version attribute from validation rules as [[\yii\behaviors\OptimisticLockBehavior|OptimisticLockBehavior]] should handle it.
4. In the Web form that takes user inputs, add a hidden field to store the current version number of the row being updated.
5. In the controller action that updates the row using Active Record, try and catch the [[yii\db\StaleObjectException]] 5. In the controller action that updates the row using Active Record, try and catch the [[yii\db\StaleObjectException]]
exception. Implement necessary business logic (e.g. merging the changes, prompting staled data) to resolve the conflict. exception. Implement necessary business logic (e.g. merging the changes, prompting staled data) to resolve the conflict.