# Delete has\_many\_and\_belongs\_to\_many relation

**URL:** <https://www.ruby-forum.com/t/delete-has-many-and-belongs-to-many-relation/100363>\
**Category:** Rails\
**Created:** [July 28, 2006, 4:22pm UTC](https://www.ruby-forum.com/t/delete-has-many-and-belongs-to-many-relation/100363 "2006-07-28T16:22:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/51bf81/32.png) [@Fab](https://www.ruby-forum.com/u/Fab)\
**Post date:** [July 28, 2006, 4:22pm UTC](https://www.ruby-forum.com/t/delete-has-many-and-belongs-to-many-relation/100363/1 "2006-07-28T16:22:35Z")

</div>

Hi there,

Just a simple question I guess, but I am unable to find an anwser…

How to delete a hmabtm relation?

Any help will be appreciated 🙂

Thanks,  
Fabrice.

---

<div class="post-metadata">

**Author:** ![Fab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/51bf81/32.png) [@Fab](https://www.ruby-forum.com/u/Fab)\
**Post date:** [July 28, 2006, 4:35pm UTC](https://www.ruby-forum.com/t/delete-has-many-and-belongs-to-many-relation/100363/2 "2006-07-28T16:35:58Z")

</div>

Fab wrote:

> Hi there,
> 
> Just a simple question I guess, but I am unable to find an anwser…
> 
> How to delete a hmabtm relation?
> 
> Any help will be appreciated 🙂
> 
> Thanks,  
> Fabrice.

Try this…

@user = User.find(session[:current\_user])  
@tag = Tag.find(params[:tag\_id])  
@tag.users.delete(@user)

where Tag habtm User

I’m pretty sure that you need to pass the actual @user object, not just  
the id,  
can’t quite remember…

Hope it helps :]

ciao  
Gustav P.  
removed\_email\_address@domain.invalid  
[itsdEx.com](http://itsdEx.com)

---

<div class="post-metadata">

**Author:** ![Fab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/51bf81/32.png) [@Fab](https://www.ruby-forum.com/u/Fab)\
**Post date:** [July 28, 2006, 4:53pm UTC](https://www.ruby-forum.com/t/delete-has-many-and-belongs-to-many-relation/100363/3 "2006-07-28T16:53:16Z")

</div>

Hi Gustav,

It works perfectly 😉  
Thanks a lot for your so quick answer.

Best regards,  
Fabrice.

gustav Paul wrote:

> Fab wrote:
> 
> > Hi there,
> > 
> > Just a simple question I guess, but I am unable to find an anwser…
> > 
> > How to delete a hmabtm relation?
> > 
> > Any help will be appreciated 🙂
> > 
> > Thanks,  
> > Fabrice.
> 
> Try this…
> 
> @user = User.find(session[:current\_user])  
> @tag = Tag.find(params[:tag\_id])  
> @tag.users.delete(@user)
> 
> where Tag habtm User
> 
> I’m pretty sure that you need to pass the actual @user object, not just  
> the id,  
> can’t quite remember…
> 
> Hope it helps :]
> 
> ciao  
> Gustav P.  
> removed\_email\_address@domain.invalid  
> [itsdEx.com](http://itsdEx.com)
