Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 返回nil的DataMapper.get(:attribute=>;value)_Ruby_Sinatra_Ruby Datamapper - Fatal编程技术网

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

Ruby 返回nil的DataMapper.get(:attribute=>;value),ruby,sinatra,ruby-datamapper,Ruby,Sinatra,Ruby Datamapper,型号: 我正在尝试按“名称”属性执行查询: Country.find(:name=>“value”) 但它总是给我返回一个nil。但事实并非如此,因为我非常确定数据库中存在具有特定值的记录 我意识到我必须做:Country.first(:name=>“value”)或Country.last(:name=>“value”) Country.get仅支持按主键或组合键进行搜索 另一种选择是:Country.all(:conditions=>{:name=>“value”}) 参考资料:我意识到我必

型号:

我正在尝试按“名称”属性执行查询:

Country.find(:name=>“value”)


但它总是给我返回一个
nil
。但事实并非如此,因为我非常确定数据库中存在具有特定值的记录

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

Country.get
仅支持按主键或组合键进行搜索

另一种选择是:
Country.all(:conditions=>{:name=>“value”})


参考资料:

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

Country.get
仅支持按主键或组合键进行搜索

另一种选择是:
Country.all(:conditions=>{:name=>“value”})

参考:

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