Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails : stack level too deep

Actually i'm on a project for a model many->many. I need to find with a current user all credits/devices/project (and I think it's useless to have a table credit with only two column (id & score) so I merge this table to the join table).

I get this error :

SystemStackError in Users#show

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

stack level too deep

And the two model :

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

Thank !

Best.

like image 370
msusplugas Avatar asked Jul 25 '12 15:07

msusplugas


1 Answers

Stack level to deep points to an infinitive recursive call, and I would say you get that with

has_many :credit, :through => :credit,

which clearly introduces a cycle of some sort.

like image 193
bento Avatar answered Sep 29 '22 03:09

bento