# Help with destroy and delete HABTM

**URL:** <https://www.ruby-forum.com/t/help-with-destroy-and-delete-habtm/125528>\
**Category:** Rails\
**Created:** [January 9, 2008, 10:56pm UTC](https://www.ruby-forum.com/t/help-with-destroy-and-delete-habtm/125528 "2008-01-09T22:56:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [January 9, 2008, 10:56pm UTC](https://www.ruby-forum.com/t/help-with-destroy-and-delete-habtm/125528/1 "2008-01-09T22:56:51Z")

</div>

I have this code in rp\_parts controlled in def destroy:

```
@repair_ticket.rp_parts.delete(@rp_part)

```

repair\_tickets and rp\_parts are HABTM.

If I do:

> > repair\_ticket1.rp\_parts  
> > =\> [#\<RpPart id: 1, …"\>, #\<RpPart id: 1,…"\>, #\<RpPart …"\>]

I only want to delete one of those RpPart id:1, and not both of them. Is  
it possible?

---

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [January 9, 2008, 11:35pm UTC](https://www.ruby-forum.com/t/help-with-destroy-and-delete-habtm/125528/2 "2008-01-09T23:35:29Z")

</div>

John S. wrote:

> I have this code in rp\_parts controlled in def destroy:
> 
> ```
> @repair_ticket.rp_parts.delete(@rp_part)
> 
> ```
> 
> repair\_tickets and rp\_parts are HABTM.
> 
> If I do:
> 
> > > repair\_ticket1.rp\_parts  
> > > =\> [#\<RpPart id: 1, …"\>, #\<RpPart id: 1,…"\>, #\<RpPart …"\>]
> 
> I only want to delete one of those RpPart id:1, and not both of them. Is  
> it possible?

Consulting the API, I found that:

.delete:  
Deletes the record with the given id without instantiating an object  
first. If an array of ids is provided, all of them are deleted.

What if I only want to delete the first one?
