[email protected] wrote:
just a quick question, cause so far I was nt able to find a nice and
Let s assume an apple belongs_to a tree.
Now I would like to be able to detect in the apple model that the tree
I would like to be able to detect changes if either apple.tree_id or
apple.tree is changed.
This is not easy, but here is a hackish solution:
Turn on optimistic locking on the Tree model. (see
) This will among other things give you a new integer field that will
change every time the record is saved. In the Apple model store the
value of lock_version field. You can then check if this value has
changed and take appropriate action. If I were doing this I would check
when an Apple was loaded and then again when it’s saved. This might
also work with a magic timestamp field.
There is (to my knowledge) no way of knowing in real time when the Tree
changes except by having the Tree itself call all the Apples that
belong_to it when it saves. (Very time consuming)