[Nitro] Possible BUG in lib/og/relation/has_many.rb (and possible fix)

Aidan Rogers aidan at yoyo.org
Thu Jan 19 16:42:03 EST 2006

Happy to help :-)

Btw, any chance my credit in Authors could be changed to  
aidan at infurious.com - I'm starting a small software company and every  
bit of publicity helps.


On 20/01/2006, at 8:30 AM, Bryan Soto wrote:

> On 1/18/06, Aidan Rogers <aidan at yoyo.org> wrote:
> One workaround is to save the owner (commented out in the above
> example) before adding, or to use 'create' instead of 'new'.  This
> ensures the owner has a primary key.  No problem in most cases.  The
> reason I discovered this (possible) bug is that I was trying to
> access the various relations of my owner class in a method that I was
> using as a post_insert - can't save in that method, otherwise I'd get
> a nasty infinite loop.
> So, one possible fix is to say in the add_* method:
>        def add_#{target_singular_name}(obj, options = nil)
>          return unless obj
>         self.save unless self.saved? # THIS LINE IS THE NEW ONE
>          obj.#{foreign_key} = @#{owner_class.primary_key}
>          obj.save
>        end
> However, this may have some unpleasant side effects that I can't
> foresee at this moment.  Can anyone shed any light on this?  Can
> anyone think of a reason this might be bad?
> Well, first thought I have is that the object, if there are failing  
> validations, might not save and the problem would still exist.
> I think we should have the object determine when it's collections  
> are saved rather than the collections saving the object.
> Strange bug part 2.
> Yaml complains with /usr/local/lib/ruby/1.8/yaml/rubytypes.rb:9:in
> `to_yaml': can't dump anonymous class Class (TypeError)
> Anyone? :-)
> You make me glad I think I've figured out why the Og unit tests  
> aren't running ;) Will, hopefully, follow up with a patch and/or  
> explanation today.
> bryan
> _______________________________________________
> Nitro-general mailing list
> Nitro-general at rubyforge.org
> http://rubyforge.org/mailman/listinfo/nitro-general

More information about the Nitro-general mailing list