我不想在这里问一栏我的模式:
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<>/code>方法时,我会发现以下错误。
Failure/Error: context2.move_up
+options[:order]+ entry 1 of an unsupported object Fixnum
# ./context.rb:11:in `move_up
尽管存在一些条件,但为什么不从事这项工作?