Forum: Ruby on Rails Delete row without th eid field

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1c814a8b18126576c774babc160d1eab?d=identicon&s=25 Sainaba Sainu (sainaba)
on 2006-01-23 06:12
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.
42bfb8fb44488c492cf6c7da1a8e1ded?d=identicon&s=25 Ben Lewis (Guest)
on 2006-01-23 06:18
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.

http://api.rubyonrails.org/classes/ActiveRecord/Base.html

~Ben
42bfb8fb44488c492cf6c7da1a8e1ded?d=identicon&s=25 Ben Lewis (Guest)
on 2006-01-23 06:18
> Check out the destroy_all method.  It may well suit your needs.
>
> http://api.rubyonrails.org/classes/ActiveRecord/Base.html
>
> ~Ben

You may also use delete_all :D
C8a634a01a2c4508360874bff7fb1a7f?d=identicon&s=25 Kevin Olbrich (olbrich)
on 2006-01-23 06:20
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
1c814a8b18126576c774babc160d1eab?d=identicon&s=25 Sainaba Sainu (sainaba)
on 2006-01-23 06:51
Hi
 it worked with

Customer.delete_all " customer_id = " +  @company_id.to_s

Thanks to all ,
Sainaba.
This topic is locked and can not be replied to.