Sql (Rails活动记录):具有结果对象字段唯一性约束的请求

Sql (Rails活动记录):具有结果对象字段唯一性约束的请求,sql,ruby-on-rails,ruby,activerecord,Sql,Ruby On Rails,Ruby,Activerecord,好的,我得到了以下简单的模型类: class Baby < ActiveRecord::Base attr_accessible :name, :born_at ... end 但是我不知道该在请求中添加什么,所以婴儿的名字应该是唯一的 免责声明:我对SQL数据库相当陌生,所以不要因为我的蹩脚问题而评判我 或者如果你只需要名字 Baby.select(:name).limit(20).order('born_at desc') 你只需要名字还是全部记录? Baby.grou

好的,我得到了以下简单的模型类:

class Baby < ActiveRecord::Base
  attr_accessible :name, :born_at
  ...
end
但是我不知道该在请求中添加什么,所以婴儿的名字应该是唯一的

免责声明:我对SQL数据库相当陌生,所以不要因为我的蹩脚问题而评判我

或者如果你只需要名字

Baby.select(:name).limit(20).order('born_at desc')

你只需要名字还是全部记录?
  Baby.group(:name).order('born_at desc').limit(20)
Baby.all(:order => 'born_at desc', :limit => 20, :group => :name)
Baby.select(:name).limit(20).order('born_at desc')