rails:堆栈级别太深

msu*_*gas 8 ruby sqlite ruby-on-rails

实际上我正在进行一个多模型的项目 - >很多.我需要找到当前用户所有的信用/设备/项目(我认为只有两个列(id和score)的表信用是没用的,所以我将这个表合并到连接表中).

我收到此错误:

SystemStackError in Users#show

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

stack level too deep
Run Code Online (Sandbox Code Playgroud)

而这两个模型:

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
Run Code Online (Sandbox Code Playgroud)

谢谢 !

最好.

ben*_*nto 15

堆栈级别到深度指向一个不定式的递归调用,我会说你得到它

has_many :credit, :through => :credit,
Run Code Online (Sandbox Code Playgroud)

这显然引入了某种循环.