【问题标题】:DataMapper.get(:attribute => value) returning nilDataMapper.get(:attribute => value) 返回 nil
【发布时间】:2012-08-05 12:29:36
【问题描述】:

型号:

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

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

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

但它一直给我回复nil。这不应该是这种情况,因为我非常确定具有特定值的记录存在于数据库中。

【问题讨论】:

    标签: ruby sinatra ruby-datamapper


    【解决方案1】:

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

    Country.get只支持按主键或复合键搜索

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-26
      • 1970-01-01
      • 2013-02-18
      • 2019-06-20
      相关资源
      最近更新 更多