<% Specimen.find(:all, :order => 'distribution_sheet_id', :limit => 10).each do |df| 开发者_JAVA技巧%>
<%= df.id %>
<% end %>
This gives this query:
SELECT * FROM "specimens" ORDER BY distribution_sheet_id LIMIT 10
I need this:
SELECT * FROM "specimens" ORDER BY distribution_sheet_id DESC LIMIT 10
I'm using Rails < 3. Any help please?
Add DESC
to the end of your order value.
Specimen.find(:all, :order => 'distribution_sheet_id DESC', :limit => 10)
Full example:
<% Specimen.find(:all, :order => 'distribution_sheet_id DESC', :limit => 10).each do |df| %>
<%= df.id %>
<% end %>
Just add DESC
Specimen.find(:all, :order => 'distribution_sheet_id DESC', :limit => 10).each do |df| %> <%= df.id
Specimen.
all(:order => 'distribution_sheet_id DESC', :limit => 10, :select => :id).
map(:&id)
精彩评论