2012-03-22 27 views

回答

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 
+0

謝謝!如果我明白了,如果沒有記錄它只是返回無 – user1136228 2012-03-22 15:59:13

+0

如果你正在尋找,你可以去'#first_or_create'。 – Reactormonk 2012-03-22 16:37:11

+0

@ user1136228是的,據我所知。 – 2012-03-22 16:54:51