Richard Livsey
2006-Jan-20 21:21 UTC
[Rails] stack level too deep from has_many / belongs_to relationship
I have the following 3 models (2 models joined by an intermediate): 1. class Exercise < ActiveRecord::Base 2. has_many :routines, :class_name=>''RoutineExercise'' 3. end 1. class Routine < ActiveRecord::Base 2. has_many :exercises, 3. :class_name=>''RoutineExercise'', 4. :order=>''position'' 5. end 1. class RoutineExercise < ActiveRecord::Base 2. set_table_name "exercises_routines" 3. set_primary_key ''join_id'' 4. 5. belongs_to :routine 6. belongs_to :exercise 7. 8. acts_as_list :scope => :routine_id 9. end From this I''m getting ''stack level too deep'' errors: #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/associations.rb:877:in `create_has_many_reflection'' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/associations.rb:346:in `has_many'' #{RAILS_ROOT}/app/models/routine.rb:2 #{RAILS_ROOT}/app/models/routine_exercise.rb:5 #{RAILS_ROOT}/app/models/routine.rb:2 ... snip ... #{RAILS_ROOT}/app/models/routine_exercise.rb:5 #{RAILS_ROOT}/app/models/routine.rb:2 #{RAILS_ROOT}/app/controllers/items_controller.rb:462:in `const_get'' #{RAILS_ROOT}/app/controllers/items_controller.rb:462:in `item_class'' #{RAILS_ROOT}/app/controllers/items_controller.rb:112:in `new'' So this seems to be getting into a recursive loop around the RoutineExercise belonging to Routine and Routine having many RoutineExercises, but I can''t work out why. Thanks in advance. -- R.Livsey http://livsey.org
Richard Livsey
2006-Jan-21 00:09 UTC
[Rails] stack level too deep from has_many / belongs_to relationship
Turns out to be a combination of edge rails and rails_engines. There''s a patch here which fixes it: https://opensvn.csie.org/traccgi/rails_engines/trac.cgi/ticket/63 Thanks. -- R.Livsey http://livsey.org Richard Livsey wrote:> I have the following 3 models (2 models joined by an intermediate): > > 1. class Exercise < ActiveRecord::Base > 2. has_many :routines, :class_name=>''RoutineExercise'' > 3. end > > 1. class Routine < ActiveRecord::Base > 2. has_many :exercises, > 3. :class_name=>''RoutineExercise'', > 4. :order=>''position'' > 5. end > > 1. class RoutineExercise < ActiveRecord::Base > 2. set_table_name "exercises_routines" > 3. set_primary_key ''join_id'' > 4. > 5. belongs_to :routine > 6. belongs_to :exercise > 7. > 8. acts_as_list :scope => :routine_id > 9. end > > From this I''m getting ''stack level too deep'' errors: > > #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/associations.rb:877:in > `create_has_many_reflection'' > #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/associations.rb:346:in > `has_many'' > #{RAILS_ROOT}/app/models/routine.rb:2 > #{RAILS_ROOT}/app/models/routine_exercise.rb:5 > #{RAILS_ROOT}/app/models/routine.rb:2 > ... snip ... > #{RAILS_ROOT}/app/models/routine_exercise.rb:5 > #{RAILS_ROOT}/app/models/routine.rb:2 > #{RAILS_ROOT}/app/controllers/items_controller.rb:462:in `const_get'' > #{RAILS_ROOT}/app/controllers/items_controller.rb:462:in `item_class'' > #{RAILS_ROOT}/app/controllers/items_controller.rb:112:in `new'' > > > So this seems to be getting into a recursive loop around the > RoutineExercise belonging to Routine and Routine having many > RoutineExercises, but I can''t work out why. > > Thanks in advance. >