Has_and_belongs_to_many delete


#1

Hi all,

I have a has_and_belongs_to_many relationship with 2 tables (users -
users_teams, teams)

Can I delete a user from a team with 1 function? I now first delete
the user from users_teams and then from teams. Can’t this be done with
one method?

Thanks

Stijn


#2

Tarscher wrote:

I have a has_and_belongs_to_many relationship with 2 tables (users -
users_teams, teams)

Can I delete a user from a team with 1 function? I now first delete
the user from users_teams and then from teams. Can’t this be done with
one method?

team.users.delete(user)


Josh S.
http://blog.hasmanythrough.com/


#3

Hi, thanks for the reply

Though I still don’t get it to work

When I do
team = Node.find(teamid)
user = User.find(userid)
team.users.delete(user)

ActiveRecord only deletes records in the users_teams table and not
users table. Is this not possible with 1 function?

Thanks
Stijn