Delete a Has-Many Relationship ONLY
Asked Answered
C

1

13

I have a: has_and_belongs_to_many :friends, :join_table => "friends_peoples".

To add a friend I do: @people.followers << @friend which create the relationship and a new person profile.

Now I'd like to delete the relationship ONLY and not the person profile.

I tried @people.friends.delete(guilty.id) but it deletes the person profile and not the relationship.

Any idea?

Catania answered 3/10, 2010 at 23:37 Comment(0)
C
25

Have you tried this?

@people.friends.delete(guilty)
Convenient answered 4/10, 2010 at 11:5 Comment(2)
Works! Was easy! Thanks a lotCatania
FYI delete skips callbacks. Use @people.friends.destroy(guilty) to get the callbacks to work.Compotation

© 2022 - 2024 — McMap. All rights reserved.