8

实际上,我正在为模型多->多做一个项目。我需要找到当前用户的所有积分/设备/项目(我认为只有两列(id & score)的表积分是没用的,所以我将此表合并到连接表)。

我收到此错误:

SystemStackError in Users#show

Showing app/views/shared/_credit.html.erb where line # raised:

stack level too deep

和两个模型:

class **Credit** < ActiveRecord::Base
  attr_accessible :created_at, :credit_id, :device_id, :project_id, :score, :user_id

belongs_to :device
belongs_to :user
belongs_to :project
belongs_to :score

end

class **User** < ActiveRecord::Base

has_many :credit
has_many :credit, :through => :credit, foreign_key: "user_id", dependent: :destroy
end

谢谢 !

最好的。

4

1 回答 1

16

堆栈级别到深度指向不定式递归调用,我会说你明白了

has_many :credit, :through => :credit,

这清楚地引入了某种循环。

于 2012-07-25T15:29:01.057 回答