Another minor Og 0.26.0 bug

This one in og/manager.rb. Took me an age to track it down. I had an array of Og managed objects, and I was calling array.include?( foo ) where foo blatantly wasn’t in the array, and it was still returning true. As it turns out, the Og manager overrides the ‘==’ method, and does it badly. … Continue reading “Another minor Og 0.26.0 bug”

This one in og/manager.rb. Took me an age to track it down. I had an array of Og managed objects, and I was calling array.include?( foo ) where foo blatantly wasn’t in the array, and it was still returning true. As it turns out, the Og manager overrides the ‘==’ method, and does it badly. Here’s the fix. It should (with luck) get rolled in to the 0.27.0 release next week.

The DON’T DO THIS!!! comment is a little scary.

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

Leave a Reply