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

George Moschovitis george.moschovitis at gmail.com
Fri Jan 13 07:47:34 EST 2006


thanks, added the fix, but as you said, this code may be removed...

-g.

On 1/13/06, Aidan Rogers <aidan at yoyo.org> wrote:
> 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
>         end
>       }
> _______________________________________________
> Nitro-general mailing list
> Nitro-general at rubyforge.org
> http://rubyforge.org/mailman/listinfo/nitro-general
>


--
http://www.gmosx.com
http://www.navel.gr
http://www.nitrohq.com




More information about the Nitro-general mailing list