Activerecord And "select For Update"

Hello,

I need to handle concurrent access to a table.

So I would like to load a specific row and lock it using "select for update".

Then I make changes to this Model and then I write it back using the save() function and so release the lock…

What is the best way to handle this using ActiveRecords?

Thanks,

Urkman

which DBMS are you using? In general you should use transactions for this. But you have to use isolation level setting of your dbms to ensure your transaction gets a read lock on the table.

There currently is no native support in Yii yet but we consider to add it soon. https://github.com/yiisoft/yii2/issues/3220

Thanks for your answer :)

I’m using PostgresSQL in Version 9.3

Check this out: http://www.postgresql.org/docs/9.1/static/transaction-iso.html

Hi,

I don’t need a read lock. It is fine, when other scripts read from the table at the same time…

I only need a write lock, so no other script should be able to start a new transaction on this row…

Greetings,

Urkman