-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AR force update #1611
Comments
What's your situation exactly? |
Added |
@samdark , I have a following situation: There is an AR Model Form with a file field. File field is perfomed in @qiangxue , thank you for your job, but I can't solve an problem with If table has only 2 fields If you don't want to set a variable $forceUpdate, what do you think about following change? $condition[$lock] = $this->$lock; to $condition[$lock] = $this->getOldAttribute($lock); I think it solves the problem. If I want to force update I will call |
Why the second will not receive the exception? If the first user saves the record first, the lock counter will be incremented by one, and when the second user tries to save the record, he will find the lock counter is outdated. |
You're right, it would have happened if first user change at least one field. But if user change only file field of the form, AR model will not be saved. So lock counter will not be incremented. |
But why don't you modify the AR model (e.g. set the update time) since the model does get changed? It seems your design is problematic... |
Setting update time is good idea. But in my task it will be unused field. When model is changed I have to update |
I think your use case is uncommon. We certainly don't want to introduce an extra property to solve this uncommon problem because it means extra memory cost (we are very careful at adding any additional new properties to base classes.) For your case, I think |
* upstream: (21 commits) Fixes yiisoft#1643: Added default value for `Captcha::options` Fixes yiisoft#1654: Fixed the issue that a new message source object is generated for every new message being translated Allow dash char in ActionColumn’s button names. Added SecurityTest. fixed functional test when enablePrettyUrl is false. fixed composer.json minor doc fix. Fixes yiisoft#1634: Use masked CSRF tokens to prevent BREACH exploits Use better random CSRF token. GII unique indexes avoid autoIncrement columns updated debug retry params. Added sleep(). Added unit test for ActiveRecord::updateAttributes(). Fixes yiisoft#1641: Added `BaseActiveRecord::updateAttributes()` Fixed yiisoft#1504: Debug toolbar isn't loaded successfully in some environments when xdebug is enabled Mongo README.md updated. Fixes yiisoft#1611: Added `BaseActiveRecord::markAttributeDirty()` Number validator was missing Fixes yiisoft#1638: prevent table names from being enclosed within curly brackets twice. Unique indexes rules for single columns into array ...
Sometimes I need to update optimistic locks's counter even if no attribute was changed. In the current version It's hard to do it.
I propose to set a variable $forceUpdate at \yii\db\BaseActiveRecord class.
Also updateInternal method should be updated.
The text was updated successfully, but these errors were encountered: