我正在尝试查询模型中的列:
require 'rubygems'
require 'dm-core'
require 'dm-migrations'
require 'dm-aggregates'
db_name = 'mydb.sqlite'
DataMapper::Logger.new($stdout, :debug)
DataMapper.setup(:default, 'sqlite://' + Dir.pwd + '/' + db_name)
class Context
include DataMapper::Resource
property :id, Serial
property :order, Integer
def initialize
self.order = (self.class.max(:order) || 0) + 1
end
def move_up
temp = self.class.first(:order => (self.order - 1))
temp.order += 1
temp.save
self.order -= 1
self.save
end
end
DataMapper.finalize
DataMapper.auto_upgrade!
但是当我创建几个实例时,我在调用move_up
方法时遇到以下错误。
Failure/Error: context2.move_up
+options[:order]+ entry 1 of an unsupported object Fixnum
# ./context.rb:11:in `move_up'
尽管有边缘条件,为什么这不起作用?
答案 0 :(得分:3)
:order是保留字,因为它是您传递给查询的选项之一。只需将其重命名为不同的东西,它就会起作用