I'm just starting out with CakePHP, and I can't find any support for implementing an optimistic locking scheme. The closest I could find was a comment on this CakePHP blog post saying that it wasn't supported in June 2008.
我刚刚开始使用CakePHP,我找不到任何支持来实现乐观锁定方案。我能找到的最接近的是对这篇CakePHP博客文章的评论,称其在2008年6月没有得到支持。
Does anyone know if that has changed, or if someone has published an extension or a tutorial on how to implement it yourself?
有没有人知道这是否已经改变,或者是否有人发布了关于如何自己实现它的扩展或教程?
For a description of optimistic locking, see this answer.
有关乐观锁定的说明,请参阅此答案。
3 个解决方案
#1
Not in the Core, and after a quick google it doesn appear that anyone is sharing a behavior if they made one. That would be my suggested tactic.
不在核心,并且在快速谷歌之后,似乎任何人都没有共享行为,如果他们做了一个。这将是我建议的策略。
#2
In the book "Practical CakePHP Projects" on chapter 10 is some code given to make your own "Magic Fields". One of them is a field for optimistic locking. I haven't tried it yet, but it looks quite good actually.
在第10章的“Practical CakePHP Projects”一书中,有一些代码用于制作你自己的“Magic Fields”。其中一个是乐观锁定领域。我还没试过,但实际上它看起来很不错。
#3
Tadashi Nakamura has posted an OptimisticLock behaviour on GitHub. It's not quite perfect, because it does the query for the last modified date before writing the changed record. That leaves you open to either silently overwriting another user's changes or hitting a deadlock. When I tried to write a behaviour like this, I wanted to include the last modified date in the update's where clause and fail if the rows affected is zero. At that time, there was no support for adding an extra condition to an update query. I haven't used PHP lately, so I don't know if that has changed.
Tadashi Nakamura在GitHub上发布了一个OptimisticLock行为。它并不完美,因为它在写入更改的记录之前对最后修改日期进行查询。这让你可以默默地覆盖其他用户的更改或者遇到死锁。当我尝试编写这样的行为时,我想在update的where子句中包含最后修改日期,如果受影响的行为零则失败。那时,不支持向更新查询添加额外条件。我最近没有使用PHP,所以我不知道这是否已经改变。
#1
Not in the Core, and after a quick google it doesn appear that anyone is sharing a behavior if they made one. That would be my suggested tactic.
不在核心,并且在快速谷歌之后,似乎任何人都没有共享行为,如果他们做了一个。这将是我建议的策略。
#2
In the book "Practical CakePHP Projects" on chapter 10 is some code given to make your own "Magic Fields". One of them is a field for optimistic locking. I haven't tried it yet, but it looks quite good actually.
在第10章的“Practical CakePHP Projects”一书中,有一些代码用于制作你自己的“Magic Fields”。其中一个是乐观锁定领域。我还没试过,但实际上它看起来很不错。
#3
Tadashi Nakamura has posted an OptimisticLock behaviour on GitHub. It's not quite perfect, because it does the query for the last modified date before writing the changed record. That leaves you open to either silently overwriting another user's changes or hitting a deadlock. When I tried to write a behaviour like this, I wanted to include the last modified date in the update's where clause and fail if the rows affected is zero. At that time, there was no support for adding an extra condition to an update query. I haven't used PHP lately, so I don't know if that has changed.
Tadashi Nakamura在GitHub上发布了一个OptimisticLock行为。它并不完美,因为它在写入更改的记录之前对最后修改日期进行查询。这让你可以默默地覆盖其他用户的更改或者遇到死锁。当我尝试编写这样的行为时,我想在update的where子句中包含最后修改日期,如果受影响的行为零则失败。那时,不支持向更新查询添加额外条件。我最近没有使用PHP,所以我不知道这是否已经改变。