[Rails] Re: Trying to delete all but most recent 10

2009-09-07 Thread Marnen Laibow-Koser
RVince 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

[Rails] Re: Trying to delete all but most recent 10

2009-09-07 Thread RVince
Ah, thanks Fred, Yes, this explains then why my other records are not being saved back -- I get it (though, this has nothing to do with the partials -- that's a different issue. In this particular issue, I am merely pruning the table when the user logs off). Thanks! -RVince On Sep 7, 8:00 am, F

[Rails] Re: Trying to delete all but most recent 10

2009-09-07 Thread Frederick Cheung
On Sep 7, 1:12 am, RVince wrote: > Hassan, > > Same problem though -- it doesn;t save them back. They just all get > deleted, nothing saved back. Here is my code (all the saves evaluate > to true, btw) and the log: As of 2.1 rails has support for partial updates - when you do a save only chang

[Rails] Re: Trying to delete all but most recent 10

2009-09-07 Thread RVince
Using MySQL 5.0.27 Community Edition, Rails 2.3.2 and MySQL adapter. --~--~-~--~~~---~--~~ 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

[Rails] Re: Trying to delete all but most recent 10

2009-09-06 Thread E. Litwin
Not sure why (or if) save is returning true, but looking at the program flow, wouldn't Rails try to do an update of each cnote since they are not new records when they are retrieved? (Rather than an insert as the OP intends.) In that case, trying to update a record that no longer exists in the da

[Rails] Re: Trying to delete all but most recent 10

2009-09-06 Thread Hassan Schroeder
On Sun, Sep 6, 2009 at 5:12 PM, RVince wrote: > Same problem though -- it doesn;t save them back. They just all get > deleted, nothing saved back. Here is my code (all the saves evaluate > to true, btw) and the log: If the save! returns true, it should be good -- what DB are using? and what vers

[Rails] Re: Trying to delete all but most recent 10

2009-09-06 Thread RVince
Hassan, Same problem though -- it doesn;t save them back. They just all get deleted, nothing saved back. Here is my code (all the saves evaluate to true, btw) and the log: puts "deleting all but 10 channelnotes" @cnotes = Channelnote.find(:all, :order => 'tstamp DESC', :limit => 10, :c

[Rails] Re: Trying to delete all but most recent 10

2009-09-06 Thread Hassan Schroeder
On Sun, Sep 6, 2009 at 2:39 PM, RVince 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; >