On Sun, Sep 6, 2009 at 2:39 PM, RVince<[email protected]> 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 ------------------------ [email protected]
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---