On Tuesday, April 22, 2014 3:56:34 PM UTC-7, Nels Nelson wrote:
>
>
> 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.
>

If the parent_id column values are different Model#== should be false.  If 
you just want to check that the primary keys are equal, use Model#===.
 

> 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.
>

If you:

1) retrieve an object from the database
2) then modify the database without going through the object

then yes, you need to refresh the object so it picks up the changes made to 
the database.
 

> 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.
>

I'm afraid I don't understand this refresh after fetch idea.  Refreshing is 
what you do to pick up changes that have occurred since fetch.  Refreshing 
directly after fetch just seems redundant to me.

If I am missing something, maybe a code example showing the problem would 
help me understand.
 

> 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.
>

Well, it depends what you want.  If you want to consider objects the same 
even if their parent ids are different, it's perfectly fine to make 
#eql?/#== not consider @values.  Make sure you change #hash as well if you 
do that.
 

> 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.
>

There's no global identity map (by design), so yes, it could be complex.

What problem are you actually trying to solve?  Your post discusses 
band-aids for symptoms, but not the problem itself. :)

Thanks,
Jeremy

>

-- 
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