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

Bryan Soto bryan.a.soto at gmail.com
Thu Jan 19 16:30:42 EST 2006

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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/nitro-general/attachments/20060119/e05845d9/attachment.html 

More information about the Nitro-general mailing list