stevemolitor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Jun-10 17:29 UTC
Intermittent Problem Persisting HABTM relationships
We are having an intermittent problem with has_and_belongs_to_many where the join table record is not created. For example, we have a HABT relationship mapped on both sides of models InFile and Sponsor. Our code looks like this: sponsor = Sponsor.find(sponsor_id) in_file = InFile.new(attributes) in_file.sponsors << sponsor in_file.save Occasionally the new join record in in_files_sponsors is not inserted. It takes a while for this to start happening, but once it starts happening it continues. We are using Rails 2.02 with Ruby 1.8.5. Thanks! Steve and Jonathan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Aaron Baldwin
2008-Jun-11 06:33 UTC
Re: Intermittent Problem Persisting HABTM relationships
Try something like this: Sponsor.find(sponsor_id).in_files << InFile.create(attributes) I''m wondering if trying to make the association before the in_file object has been saved is causing the problem. But I can''t explain why that would only cause an intermittent problem. Aaron On Jun 10, 11:29 am, "stevemoli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <stevemoli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> We are having an intermittent problem with has_and_belongs_to_many > where the join table record is not created. For example, we have a > HABT relationship mapped on both sides of models InFile and Sponsor. > Our code looks like this: > > sponsor = Sponsor.find(sponsor_id) > in_file = InFile.new(attributes) > in_file.sponsors << sponsor > in_file.save > > Occasionally the new join record in in_files_sponsors is not > inserted. It takes a while for this to start happening, but once it > starts happening it continues. We are using Rails 2.02 with Ruby > 1.8.5. > > Thanks! > > Steve and Jonathan--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---