我有一个大而复杂的用户模型,看起来像这样:
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,用户也不会被销毁。没有任何类型的错误消息。我是否缺少某种级联删除命令?