# Delete row without th eid field

**URL:** <https://www.ruby-forum.com/t/delete-row-without-th-eid-field/64365>\
**Category:** Rails\
**Created:** [January 23, 2006, 6:12am UTC](https://www.ruby-forum.com/t/delete-row-without-th-eid-field/64365 "2006-01-23T06:12:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sainaba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@sainaba](https://www.ruby-forum.com/u/sainaba)\
**Post date:** [January 23, 2006, 6:12am UTC](https://www.ruby-forum.com/t/delete-row-without-th-eid-field/64365/1 "2006-01-23T06:12:22Z")

</div>

Hi all,

I have a table structure with me not having an id column. When I try to  
delete the row i get an error ‘Unknown column “table.id”’. Can i do the  
action with any other method than destroy/delete? Or with the same  
method and any other conditions?

Thanks.  
Sainaba.

---

<div class="post-metadata">

**Author:** ![sainaba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@sainaba](https://www.ruby-forum.com/u/sainaba)\
**Post date:** [January 23, 2006, 6:18am UTC](https://www.ruby-forum.com/t/delete-row-without-th-eid-field/64365/2 "2006-01-23T06:18:02Z")

</div>

sainaba sainu wrote:

> Hi all,
> 
> I have a table structure with me not having an id column. When I try to  
> delete the row i get an error ‘Unknown column “table.id”’. Can i do the  
> action with any other method than destroy/delete? Or with the same  
> method and any other conditions?
> 
> Thanks.  
> Sainaba.

Check out the destroy\_all method. It may well suit your needs.

> **[ActiveRecord::Base](https://api.rubyonrails.org/classes/ActiveRecord/Base.html)**
>
> Active Record Active Record objects don't specify their attributes directly, but rather infer them from the table definition with which they're linked.

~Ben

---

<div class="post-metadata">

**Author:** ![sainaba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@sainaba](https://www.ruby-forum.com/u/sainaba)\
**Post date:** [January 23, 2006, 6:20am UTC](https://www.ruby-forum.com/t/delete-row-without-th-eid-field/64365/3 "2006-01-23T06:20:19Z")

</div>

sainaba sainu wrote:

> Hi all,
> 
> I have a table structure with me not having an id column. When I try to  
> delete the row i get an error ‘Unknown column “table.id”’. Can i do the  
> action with any other method than destroy/delete? Or with the same  
> method and any other conditions?
> 
> Thanks.  
> Sainaba.

Change the line that looks up your record in the delete function to use  
your own primary key.

instead of something like

@item = Item.find(params[:id])

it will be something like

@item = Item.find(params[:name])

or

@item = Item.find\_by\_name(paranms[:name])

Depends on how you have your table set up.

\_Kevin

---

<div class="post-metadata">

**Author:** ![sainaba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@sainaba](https://www.ruby-forum.com/u/sainaba)\
**Post date:** [January 23, 2006, 6:51am UTC](https://www.ruby-forum.com/t/delete-row-without-th-eid-field/64365/4 "2006-01-23T06:51:08Z")

</div>

Hi  
it worked with

Customer.delete\_all " customer\_id = " + @company\_id.to\_s

Thanks to all ,  
Sainaba.

---

<div class="post-metadata">

**Author:** ![sainaba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@sainaba](https://www.ruby-forum.com/u/sainaba)\
**Post date:** [January 23, 2006, 6:18am UTC](https://www.ruby-forum.com/t/delete-row-without-th-eid-field/64365/5 "2006-01-23T06:18:54Z")

</div>

> Check out the destroy\_all method. It may well suit your needs.
> 
> [ActiveRecord::Base](http://api.rubyonrails.org/classes/ActiveRecord/Base.html)
> 
> ~Ben

You may also use delete\_all 😃
