ruby on rails - How can I delete some data from DB if there is no primary key? -


using ror 3.0.7. (ruby 1.9.2)

i have table books (model book) following fields:

book_id - int (not primary key)

cover_pic - varchar

year - year

i need delete * rows db books_id = 1 example.

have tried:

1) book.where(:book_id=>1).destroy (nothing)

2) book.destroy( book.where(:book_id=>1) ) (nothing)

3) book.where(:book_id=>1).each |obj|

obj.destroy

end

nothing .. =(

what doing wrong?

thx.

upd

worked fine delete_all

interesting info: undefined method `eq' nil:nilclass rails 3 , ruby enterprise on ubuntu hardy

you can use either of these two:

this fire destroy callbacks

book.destroy_all( :book_id => 1 )  

this won't

book.delete_all( :book_id => 1 )  

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -