bitsweat.net/svn/object_transactions.
Locking
Active Record supports two forms of locking, optimistic and pessimistic. In Active Record,
optimistic locking means that the database records are versioned, and before an objects is
actually saved back to the database record, the version you are saving is checked against the
version in the database to make sure the model was not otherwise modified while you were
working on it. If it was modified, an exception is raised. The other type of locking in Active Record,
pessimistic locking, is simply row-level locking, as supported by the database.
CHAPTER 2 ?– ACTIVE RECORD AND SQL 40
Optimistic Locking
As previously mentioned, optimistic locking in Active Record is accomplished by keeping track
of which version of a model you are working with. The use of optimistic locking is triggered
simply by adding a column named lock_version to your model??™s database table.
?– Tip You are responsible for ensuring that the database schema defaults the lock_version column to 0.
Additionally, you can use a different column name by calling the set_locking_column method in your model.
Pages:
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131