[Nitro] BUG + PATCH: Comparison of managed Og objects

Aidan Rogers aidan at yoyo.org
Fri Jan 13 06:53:55 EST 2006

I had an annoying bug where I had an array of Og managed objects, and  
calling array.include?( obj ) on an object that blatantly wasn't in  
the array was returning true.

As it turns out, in manager.rb there is a redefinition for the '=='  
method, which is buggy - it compares the primary keys of the two  
objects but doesn't compare their classes.

Here is a fix.

My one possible issue is that there is a great big DON'T DO THIS!!!  
comment just before that particular area of the code.  Is this  
something that perhaps needs removing altogether?

Anyway, the fix now compares class types and then primary keys.

Aidan (a.k.a. five on #nitro)

--- manager.rb  2006-01-13 22:49:03.000000000 +1100
+++ /tmp/manager.rb     2006-01-13 22:48:53.000000000 +1100
@@ -104,7 +104,11 @@
      # DON'T DO THIS!!!
      klass.module_eval %{
        def ==(other)
-        other ? @#{klass.primary_key.symbol} == other.# 
{klass.primary_key.symbol} : false
+               if( other.instance_of?(#{klass}) && @# 
{klass.primary_key.symbol} == other.#{klass.primary_key.symbol} )
+                       true
+               else
+                       false
+               end

More information about the Nitro-general mailing list