目前我将rails 2应用程序升级到rails 3.2.13,它使用acts_as_tree和acts_as_list。之前,升级它运行良好。因为,我对acts_as_tree 和acts_as_list 有依赖破坏的问题。
我必须模型:
class User < ActiveRecord::Base
has_many :categories, dependent: :destroy
end
class Category < ActiveRecord::Base
acts_as_tree
acts_as_list scope: [:user_id, :parent_id]
belongs_to :user
end
鉴于我有一个用户:
<User id:1>
有 2 个类别,其中一个类别是另一个类别的子类别:
<Category id:1 parent_id:nil user_id:1>
<Category id:2 parent_id:1 user_id:1>
当我尝试销毁用户时,dependent: :destroy
尝试销毁类别。它破坏了第一类。由于该类别有一个孩子(id 2)acts_as_tree 也将其销毁。但后来似乎acts_as_list 试图重新加载第二类的位置。自然,它不再存在,所以它提出:
Couldn't find Category with id=2
gems/activerecord-3.2.13/lib/active_record/relation/finder_methods.rb:343:in `find_one'
gems/activerecord-3.2.13/lib/active_record/relation/finder_methods.rb:314:in `find_with_ids'
gems/activerecord-3.2.13/lib/active_record/relation/finder_methods.rb:107:in `find'
gems/activerecord-3.2.13/lib/active_record/querying.rb:5:in `find'
...
gems/activerecord-3.2.13/lib/active_record/autosave_association.rb:226:in `reload'
gems/acts_as_list-0.2.0/lib/acts_as_list/active_record/acts/list.rb:409:in `reload_position'
gems/activesupport-3.2.13/lib/active_support/callbacks.rb:418:in `_run__108545607483159770__destroy__3935615418128680560__callbacks'
...
gems/activerecord-3.2.13/lib/active_record/callbacks.rb:254:in `destroy'
gems/activerecord-3.2.13/lib/active_record/transactions.rb:254:in `block in destroy'
gems/activerecord-3.2.13/lib/active_record/transactions.rb:313:in `block in with_transaction_returning_status'
gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
gems/activerecord-3.2.13/lib/active_record/transactions.rb:208:in `transaction'
gems/activerecord-3.2.13/lib/active_record/transactions.rb:311:in `with_transaction_returning_status'
gems/activerecord-3.2.13/lib/active_record/transactions.rb:254:in `destroy'
任何人都有解决它的想法?
PS:Rails 3.2.13、Ruby 1.9.3、acts_as_tree 1.4.0 和acts_as_list 0.2.0