我有一个庞大而复杂的用户模型,看起来像这样:
class User
class Link
include DataMapper::Resource
property :id, Serial, :key => false
belongs_to :follower, :model => 'User', :key => true
belongs_to :followed, :model => 'User', :key => true
end
include DataMapper::Resource
property :id, Serial
property :username, String, :required => true
has n, :links_to_followers, :model => 'User::Link', :child_key => [:followed_id]
has n, :links_to_followed, :model => 'User::Link', :child_key => [:follower_id]
has n, :comments
has 1, :profile_image
end我的问题是Datamapper不让我销毁它。我认为这是Datamapper不想销毁具有未销毁的子对象的对象的结果,所以我放入了一个方法destroy_deep,该方法在links_to_followers、links_to_followed、底层注释和配置文件图像上调用destroy (这些都被正确销毁)。
然而,即使我在那之后调用user.destroy,用户也不会被销毁。没有任何类型的错误消息。有没有我遗漏的某种级联删除命令?
发布于 2012-10-19 06:36:00
我解决了这个问题。
显然,为了调试销毁,object.errors是没有用的。取而代之的是跟踪异常,如:
begin
u.destroy
rescue Exception => e
p e
end解决方案是其中一个子字段没有映射回User。我有一个属于User的类,但是User没有n个赞。
https://stackoverflow.com/questions/12867828
复制相似问题