I''m experiencing an issue with duplicate entries being added when using `has_and_belongs_to_many` in my models. I''ve setup the following test Rails project (v3.0.7) here: https://github.com/mhayes/waterclub The test case which is failing is: https://github.com/mhayes/waterclub/blob/master/test/unit/invoice_test.rb Here''s where I think the issue may reside: https://github.com/mhayes/waterclub/blob/master/app/models/invoice.rb I noticed there were threads in the past with a HABTM duplication error, so I''m not sure if this is a regression of if I''m doing something wrong. Any ideas? Please let me know if I should provide any additional information, thanks! -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On May 13, 10:05 pm, Mark H <m...-QrnBXRe0sHdWk0Htik3J/w@public.gmane.org> wrote:> I''m experiencing an issue with duplicate entries being added when using > `has_and_belongs_to_many` in my models. I''ve setup the following test Rails > project (v3.0.7) here: > > https://github.com/mhayes/waterclub > > The test case which is failing is:https://github.com/mhayes/waterclub/blob/master/test/unit/invoice_tes... > > Here''s where I think the issue may reside:https://github.com/mhayes/waterclub/blob/master/app/models/invoice.rb > > I noticed there were threads in the past with a HABTM duplication error, so > I''m not sure if this is a regression of if I''m doing something wrong. Any > ideas? Please let me know if I should provide any additional information, > thanks!is it because your fixture files define two members that are active (so they get added to the invoice too) ? Fred -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Hey Fred, Nice catch, I went ahead and updated my fixtures file (so that no active members are created). However I''m still running into the same issue :( https://github.com/mhayes/waterclub/commit/35e985ab5e09f6c40b576991838f901cc5e5247d -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On May 13, 11:10 pm, Mark H <m...-QrnBXRe0sHdWk0Htik3J/w@public.gmane.org> wrote:> Hey Fred, > > Nice catch, I went ahead and updated my fixtures file (so that no active > members are created). However I''m still running into the same issue :( > > https://github.com/mhayes/waterclub/commit/35e985ab5e09f6c40b57699183...So what are the members this newly created invoice has? Fred -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Hey Fred, When attempting to save the members with this newly created invice the HABTM relation was trying to add the same member (member_id=1 in my case) twice. However I setup a unique index on the composite key (member_id, invoice_id) so I end up with a SQLite3 ConstraintError being thrown (which I expected). On another note I just changed my code to include a Participation model that I''m using to support the many-to-many relationship between Member and Invoice. Using `has_many :members, :through => :participations` works without trying to create duplicate Member entries. So I''m not sure if this is an issue with HABTM or my code. Related changes can be found here: https://github.com/mhayes/waterclub/commit/ef74f18a62dcfa65cb009f64f96c62a99115a569 So everything is working as expected now, just a little bit differently than I would''ve hoped. Thanks for the tips! -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.