Recently I noticed that when using rcte_tree, == and eql? fail if the same
object has different parents.

Line 1203 of model/base.rb uses eql? as a delegate of ==, and defines
eql? this way:

    def eql?(obj)
      (obj.class == model) && (obj.values == @values) 
    end

Because parent_id is a key-entry of @values, two objects which are
otherwise identical, but which have different cached parent_id values
will fail an equality test.

To work around this I have to invoke refresh on at least one operand,
and probably both to be safe, prior to an equality check operation.

In my case, the instances which I am attempting to compare are
often retrieved from one of the tree member accessor methods like
parent, or children.  However, these often seem to return instances
with an outdated parent_id, especially if a node has been moved from
one branch to another.

Using the rcte_tree, is there a way to automatically refresh an instance
before returning it from any of the tree member accessor methods?

Something like, Model.always_refresh_upon_fetch = true, or whatever?
I realize this could cause a slow-down during runtime, depending on the
number of retrievals using such methods.

Else, I might try to override the eql? method of the base class so that
values were still compared sans parent_id should it be detected that
rcte_tree is in effect.  But that seems potentially dangerous.

Perhaps there would be a way to notify all references to a particular
node instance if its parent changes, and then have each reference
refresh itself.  But that could complex.

Thanks,
-Nels

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to