Datamapper类似于find_by_方法

时间:2012-03-22 10:42:27

标签: activerecord sinatra datamapper

Datamapper中是否存在ActiveRecord的find_by_方法的模拟 例如:@user = User.find_by_email(params[:email])

1 个答案:

答案 0 :(得分:2)

根据datamapper documentation和我的方式,您可以这样做:

@user = User.first(:email => params[email]) #strictly the same as find_by_email in Activerecord
@user = User.all(:email => params[email]) #strictly the same as find_all_by_email in Activerecord
@user = User.last(:email => params[email]) #no real equivalent in Active Record