marcj / optimistic-locking-behavior
A behavior allowing you to use optimistic locking in Propel 2.
Installs: 101 137
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 4
Forks: 0
Open Issues: 0
Requires
- propel/propel: 2.0.*@dev
Requires (Dev)
- phpunit/phpunit: ~4.0
This package is auto-updated.
Last update: 2024-12-11 00:38:30 UTC
README
OptimisticLockingBehavior
A behavior for Propel2 for optimistic locking.
Usage
<table name="user"> <column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" /> <column name="username" type="VARCHAR" size="100" primaryString="true" /> <behavior name="optimistic_locking" /> </table>
If you haven't installed this behavior through composer, you need to specify the full class name as behavior name:
<behavior name="\MJS\OptimisticLocking\OptimisticLockingBehavior">
You can define a different locking columns. Default is version
.
<behavior name="optimistic_locking" /> <parameter name="version_column" value="locked_version"/> </behavior>
$user = UserQuery::create()->findById($id); $user->setUsername('Secret'); try { $user->save(); } catch (\MJS\OptimisticLocking\StaleObjectException $e) { //react on that case. Maybe show the edit form again with a hint //or reload $user and apply again your changes. } if (!$user->optimisticSave(){ //whoops, there was someone faster. }
Note for Versionable
This behavior is compatible to versionable-behavior. Make sure optimistic_locking
behavior is loaded before versionable
.
<behavior name="optimistic_locking" /> <behavior name="versionable" />