[Rails] Re: HABTM Duplication
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@googlegroups.com.
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.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home