Robert Walker wrote: [...] >> a.bs << b >> a.bs << b >> a.bs << b > > This is somewhat unclear, but it appears from your code this is adding > the same b three times. So yes, if you did exactly as shown all three > association to that same b would be deleted.
This appears to be what Dino was asking. > > a.bs << b1 > a.bs << b2 > a.bs << b3 > > a.bs.delete(b2) would properly delete only b2 and leaving b1 and b3. > This is expected behavior. The only thing I don't like about how Rails > handles this is that << will create copies of the same associations. So > I typically add a unique index across the two primary keys of the join > table to prevent duplicating associations. Yeah, that makes a lot of sense. I tended to do that on join tables before I ever heard of Rails. > That being said, I also use > has_many :through in all cases (as Greg mentioned). I basically pretend > HABTM does not exist. This, on the other hand, makes no sense at all to me. For a simple habtm, nothing at all is gained by using has_many :through instead. If you outgrow the simple habtm, refactoring to has_many at that time is quick and easy. I agree that habtm is very limited, but it's a nice shortcut where it works. There's no reason to avoid it entirely. Best, -- Marnen Laibow-Koser http://www.marnen.org [email protected] -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

