# Has\_and\_belongs\_to\_many delete

**URL:** <https://www.ruby-forum.com/t/has-and-belongs-to-many-delete/84382>\
**Category:** Rails\
**Created:** [February 3, 2007, 8:45pm UTC](https://www.ruby-forum.com/t/has-and-belongs-to-many-delete/84382 "2007-02-03T20:45:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [February 3, 2007, 8:45pm UTC](https://www.ruby-forum.com/t/has-and-belongs-to-many-delete/84382/1 "2007-02-03T20:45:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [February 4, 2007, 5:44pm UTC](https://www.ruby-forum.com/t/has-and-belongs-to-many-delete/84382/2 "2007-02-04T17:44:54Z")

</div>

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/](http://blog.hasmanythrough.com/)

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [February 7, 2007, 5:27pm UTC](https://www.ruby-forum.com/t/has-and-belongs-to-many-delete/84382/3 "2007-02-07T17:27:03Z")

</div>

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
