How can I add FOR UPDATE to a cakephp3 query?

1.6k views Asked by At

Is there a way to add FOR UPDATE to a find (SELECT) query in cakephp3?

I found this hack: http://bakery.cakephp.org/2012/04/14/SELECT-FOR-UPDATE-hack-kind-of-ugly-but-it-works-PostgreSQL-and-MySql.html but it does not work since the limit value must contain only of a number. Another discussion on a similar topic can be found under https://github.com/cakephp/cakephp/issues/3136#event-213462937.

2

There are 2 answers

2
José Lorenzo Rodríguez On BEST ANSWER

You can do it with Query::epilog()

$selectQuery->...->epilog('FOR UPDATE');
0
klickagent.ch On

I opened a ticket for this for cakephp3 https://github.com/cakephp/cakephp/issues/6772#issuecomment-110530303.

The solution is to use the epilog method from the Query class:

$article->find('first')->epilog('FOR UPDATE');