开发者

Find last order limit

开发者 https://www.devze.com 2023-02-22 10:38 出处:网络
<% Specimen.find(:all, :order => \'distribution_sheet_id\', :limit => 10).each do |df| 开发者_JAVA技巧%>
<% 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)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号