2012-08-05 33 views
0

型號:DataMapper.get(:屬性=>值)返回nil

class Country 
    include DataMapper::Resource 
    property :id, Serial 
    property :name, String 
    property :continent, String 
end 

我試圖通過name屬性做一個查詢:

Country.find(:name => "value")

但它一直返回我一個nil。這不應該是這種情況,因爲我非常確定具有特定價值的記錄存在於數據庫中。

回答

2

我發現我必須做的:Country.first(:name => "value")Country.last(:name => "value")

Country.get僅支持由主鍵或複合鍵

和替代搜索:Country.all(:conditions => { :name => "value" })

參考:http://datamapper.org/docs/find.html