On Sun, Sep 6, 2009 at 2:39 PM, RVince<rvinc...@hotmail.com> wrote: > > I have a table where I am trying to delete all but the 10 most recent > records. My code is as follows: > > cnotes = Channelnote.find(:all, :order => 'tstamp DESC', :limit => > 10, :conditions => ["deleted=0"]) > Channelnote.delete_all; > for cnote in cnotes do > g=cnote.save > end > > However, it deletes ALL records in the table, seeming to NOT write > cnotes back.
More idiomatically -- @cnotes = Channelnote.find(:all, :order => 'tstamp DESC', :limit => 10, :conditions => ["deleted=0"]) Channelnote.delete_all; @cnotes.each { |cnote| cnote.save! } The save! will let you know why the save failed (failing validation, or...) -- Hassan Schroeder ------------------------ hassan.schroe...@gmail.com twitter: @hassan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---