不能对符号使用条件。带有 Sinatra 的 DataMapper
Can't use conditions on symbols. DataMapper with Sinatra
我在 DataMapper 中尝试对符号使用条件时遇到了麻烦:
clusters = Cluster.all(:latitude.not => nil)
此代码引发错误:
ArgumentError - condition #<Origin::Key:0x50d05a0 @name=:latitude, @strategy=:__override__, @operator="$not", @expanded=nil, @block=
nil> of an unsupported object Origin::Key:
C:/Ruby21/lib/ruby/gems/2.1.0/gems/dm-core-1.2.1/lib/dm-core/query.rb:888:in `block in assert_valid_conditions'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/dm-core-1.2.1/lib/dm-core/query.rb:853:in `each'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/dm-core-1.2.1/lib/dm-core/query.rb:853:in `assert_valid_conditions'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/dm-core-1.2.1/lib/dm-core/query.rb:776:in `block in assert_valid_options'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/dm-core-1.2.1/lib/dm-core/query.rb:766:in `each'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/dm-core-1.2.1/lib/dm-core/query.rb:766:in `assert_valid_options'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/dm-core-1.2.1/lib/dm-core/query.rb:363:in `update'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/dm-core-1.2.1/lib/dm-core/query.rb:386:in `merge'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/dm-core-1.2.1/lib/dm-core/model.rb:767:in `scoped_query'
集群模型class:
class Cluster
include DataMapper::Resource
property :id, Serial
property :city_id, Integer
property :name, String
property :latitude, Float
property :longitude, Float
end
核心 gem 我正在使用的版本:sinatra
- 1.4.6,data_mapper
- 1.2.0.
这段代码有什么问题?无法解决此错误。
你可以这样做:
clusters = Cluster.all - Cluster.all(:latitude => nil)
Reference(组合查询 13)
我在 DataMapper 中尝试对符号使用条件时遇到了麻烦:
clusters = Cluster.all(:latitude.not => nil)
此代码引发错误:
ArgumentError - condition #<Origin::Key:0x50d05a0 @name=:latitude, @strategy=:__override__, @operator="$not", @expanded=nil, @block=
nil> of an unsupported object Origin::Key:
C:/Ruby21/lib/ruby/gems/2.1.0/gems/dm-core-1.2.1/lib/dm-core/query.rb:888:in `block in assert_valid_conditions'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/dm-core-1.2.1/lib/dm-core/query.rb:853:in `each'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/dm-core-1.2.1/lib/dm-core/query.rb:853:in `assert_valid_conditions'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/dm-core-1.2.1/lib/dm-core/query.rb:776:in `block in assert_valid_options'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/dm-core-1.2.1/lib/dm-core/query.rb:766:in `each'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/dm-core-1.2.1/lib/dm-core/query.rb:766:in `assert_valid_options'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/dm-core-1.2.1/lib/dm-core/query.rb:363:in `update'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/dm-core-1.2.1/lib/dm-core/query.rb:386:in `merge'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/dm-core-1.2.1/lib/dm-core/model.rb:767:in `scoped_query'
集群模型class:
class Cluster
include DataMapper::Resource
property :id, Serial
property :city_id, Integer
property :name, String
property :latitude, Float
property :longitude, Float
end
核心 gem 我正在使用的版本:sinatra
- 1.4.6,data_mapper
- 1.2.0.
这段代码有什么问题?无法解决此错误。
你可以这样做:
clusters = Cluster.all - Cluster.all(:latitude => nil)
Reference(组合查询 13)