0

我在 Rails 2 项目中的关联如下:

class Role < ActiveRecord::Base
  belongs_to :user
  has_many :attrs, :through => :user, :dependent => :destroy
end

class User < ActiveRecord::Base
  has_many :roles, :order => 'id DESC', :dependent => :destroy
  has_many :attr, :dependent => :destroy
end

class Attr < ActiveRecord::Base
  belongs_to :user
  has_many :roles, :through => :user
end

我正在将我的项目升级到 rails 3。在尝试删除 rails 3 中的用户时,我收到以下错误:

无法修改关联“角色#attrs”,因为源反射类“属性”通过:has_many 关联到“用户”。

但是对于同样的事情,在 rails 2 中,用户会被很好地删除。我从来没有在rails 2上工作过,所以我不得不在这里问。

我能做些什么来解决这个问题?我检查了其他答案,但它们似乎不适用于我的情况。

4

1 回答 1

0

在用户模型中 has_many :attr, :dependent => :destroy

它应该是 has_many :attrs, :dependent => :destroy

于 2013-09-06T10:38:24.627 回答