dinoD wrote:
>> b = B.first # Find the b you want to remove association to.
>> a.bs.delete(b)
>>
>> From has_and_belongs_to_many doc:
>>
>> collection.delete(object, �)
>> Removes one or more objects from the collection by removing their
>> associations from the join table.
> 
> thanks for the reply, unfortunately this deletes ALL of them from the
> association table.  any other ideas?
> 
> thanks again,
> dino

If it does then you're doing something wrong. I just tried this in a 
test app and it work as advertised.

> 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.

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. That being said, I also use 
has_many :through in all cases (as Greg mentioned). I basically pretend 
HABTM does not exist.
-- 
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to