<% Specimen.find(:all, :order => 'distribution_sheet_id', :limit => 10).each do |df| %>
<%= df.id %>
<% end %>
这给出了这个查询:
SELECT * FROM "specimens" ORDER BY distribution_sheet_id LIMIT 10
我需要这个:
SELECT * FROM "specimens" ORDER BY distribution_sheet_id DESC LIMIT 10
我正在使用Rails&lt;请帮忙吗?
答案 0 :(得分:3)
将DESC
添加到订单值的末尾。
Specimen.find(:all, :order => 'distribution_sheet_id DESC', :limit => 10)
完整示例:
<% Specimen.find(:all, :order => 'distribution_sheet_id DESC', :limit => 10).each do |df| %>
<%= df.id %>
<% end %>
答案 1 :(得分:0)
只需添加DESC
Specimen.find(:all, :order => 'distribution_sheet_id DESC', :limit => 10).each do |df| %> <%= df.id
答案 2 :(得分:0)
Specimen.
all(:order => 'distribution_sheet_id DESC', :limit => 10, :select => :id).
map(:&id)