繁体   English   中英

DataMapper.get(:attribute => value)返回nil

[英]DataMapper.get(:attribute => value) returning nil

模型:

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

我正在尝试通过name属性进行查询:

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

但这总是让我nil 事实并非如此,因为我非常确定数据库中存在具有特定值的记录。

我意识到我必须做: Country.first(:name => "value")Country.last(:name => "value")

Country.get仅支持通过主键或复合键进行搜索

另一个选择是: Country.all(:conditions => { :name => "value" })

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM