dev-master
9999999-devA behavior allowing you to use optimistic locking in Propel 2.
The Requires
The Development Requires
Wallogit.com
2017 © Pedro Peláez
A behavior allowing you to use optimistic locking in Propel 2.
A behavior for Propel2 for optimistic locking., (*1)
<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:, (*2)
<behavior name="\MJS\OptimisticLocking\OptimisticLockingBehavior">
You can define a different locking columns. Default is version., (*3)
<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.
}
This behavior is compatible to versionable-behavior. Make sure optimistic_locking behavior is loaded before versionable., (*4)
<behavior name="optimistic_locking" /> <behavior name="versionable" />
A behavior allowing you to use optimistic locking in Propel 2.