奇怪的DataMapper问题

时间:2012-12-11 11:22:50

标签: ruby datamapper ruby-datamapper

我有一个关联模型,当我尝试删除一条记录时,它返回true但记录仍然存在,

该模型有两列keys,第三列是enum,也是一个键。

有关在DataMapper中更新/删除关联模型的任何提示

class A
   #some property definition
end

class B
   #some property definition
end

class C
  include DataMapper::Resource
  include DataMapper::Grape::Resource

  expose :type

  property :type, Enum[:a, :b], :key => true, :unique => false

  belongs_to :a, :key => true
  belongs_to :b, :key => true

end

在racksh内

element = C.get(:a,1,1)
# => returns Hash Object
# Fine till now
element.destroyed?
# => true
# I dont know why did it return true, I am 100% sure I havent performed destroy or destroy! on element
element.type
# => :a
element.type = :b
# => DataMapper::ImmutableError: Immutable resource cannot be modified
element.destroy!
# => true
C.get(:a,1,1)
# => the same Hash Object rather than returning nil

0 个答案:

没有答案