Has_and_belongs_to_many question

Ok, this is making me feel really dumb.

I have Users. I have TrainingEvents. I have a join table called
training_events_users which contains a user_id and a training_event
id.

Users habtm TrainingEvents and TrainingEvents habtm Users. My tests
work almost perfectly [1].

However, when I load the site in a web browser, I get a “stack level
too deep” error [2].

Any ideas? I’m using edge Rails.

Thanks,
Joe

[1]
This test fails on the second line. @bob is a User, and @seattle is a
training event.
assert @bob.training_events.include?(@seattle)
assert @seattle.users.include?(@bob)

@seattle.users does contain @bob, but it’s a new @bob object that
contains a @training_event that contains a @bob, if that makes sense.

[2]
./script/…/config/…/vendor/rails/activerecord/lib/active_record/validations.rb:682:in
|' ./script/../config/../vendor/rails/activerecord/lib/active_record/validations.rb:682:inwrite_inheritable_set’
./script/…/config/…/vendor/rails/activerecord/lib/active_record/validations.rb:240:in
validate_on_create' ./script/../config/../vendor/rails/activerecord/lib/active_record/validations.rb:379:invalidates_presence_of’
./script/…/config/…/vendor/rails/activerecord/lib/active_record/validations.rb:378:in
validates_presence_of' /Users/joe/Projects/cisv/trunk/vendor/plugins/login_engine/lib/login_engine/authenticated_user.rb:16:inincluded’
/Users/joe/Projects/cisv/trunk/vendor/plugins/login_engine/lib/login_engine/authenticated_user.rb:9:in
included' #{RAILS_ROOT}/app/models/user.rb:2 (eval):5:inhas_and_belongs_to_many’
#{RAILS_ROOT}/app/models/training_event.rb:3
(eval):5:in has_and_belongs_to_many' #{RAILS_ROOT}/app/models/user.rb:13 (eval):5:inhas_and_belongs_to_many’
#{RAILS_ROOT}/app/models/training_event.rb:3
(eval):5:in has_and_belongs_to_many' #{RAILS_ROOT}/app/models/user.rb:13 (eval):5:inhas_and_belongs_to_many’
#{RAILS_ROOT}/app/models/training_event.rb:

Can I clarify this question somehow?

On 11/26/05, Joe Van D. [email protected] wrote:

Can I clarify this question somehow?

Ok, to recap:

create_table :training_events do |t|
  ... event stuff
end

create_table :training_events_users do |t|
  t.column :user_id, :int
  t.column :training_event_id, :int
  t.column :created_on, :datetime
  t.column :modified_on, :datetime
end

create_table :users do |t|
  ... user stuff
end

class User < ActiveRecord::Base
has_and_belongs_to_many :training_events

end

class TrainingEvent < ActiveRecord::Base
has_and_belongs_to_many :users
end

The error:
SystemStackError in #

stack level too deep

./script/…/config/…/vendor/rails/activesupport/lib/active_support/inflector.rb:107:in
singularize' ./script/../config/../vendor/rails/activesupport/lib/active_support/inflector.rb:107:insingularize’
./script/…/config/…/vendor/rails/activerecord/lib/active_record/associations.rb:693:in
associate_identification' ./script/../config/../vendor/rails/activerecord/lib/active_record/associations.rb:353:inhas_many_without_reflection’
(eval):5:in has_many' #{RAILS_ROOT}/app/models/chapter.rb:2 (eval):5:inbelongs_to’
#{RAILS_ROOT}/app/models/training_event.rb:4
(eval):5:in has_many' #{RAILS_ROOT}/app/models/chapter.rb:2 (eval):5:inbelongs_to’
#{RAILS_ROOT}/app/models/training_event.rb:4
(eval):5:in has_many' #{RAILS_ROOT}/app/models/chapter.rb:2 (eval):5:inbelongs_to’
#{RAILS_ROOT}/app/models/training_event.rb:4
(eval):5:in has_many' #{RAILS_ROOT}/app/models/chapter.rb:2 (eval):5:inbelongs_to’
#{RAILS_ROOT}/app/models/training_event.rb:4
(eval):5:in has_many' #{RAILS_ROOT}/app/models/chapter.rb:2 (eval):5:inbelongs_to’

Hi !

2005/11/27, Joe Van D. [email protected]:

SystemStackError in #

Update to r3168. I have the same error, and r3169 is the revision
that’s causing the problem, although it seems unrelated. Haven’t had
time to investigate at the moment.

Take a look at
http://thread.gmane.org/gmane.comp.lang.ruby.rails.core/10

Bye !

Ah, thank you. That may have been it.

On 11/27/05, Joe Van D. [email protected] wrote:

  t.column :user_id, :int

has_and_belongs_to_many :training_events

end

class TrainingEvent < ActiveRecord::Base
has_and_belongs_to_many :users
end

Whoops, I posted the wrong error before. Here’s the correct one:

SystemStackError in #

stack level too deep

./script/…/config/…/vendor/rails/activerecord/lib/active_record/validations.rb:682:in
|' ./script/../config/../vendor/rails/activerecord/lib/active_record/validations.rb:682:inwrite_inheritable_set’
./script/…/config/…/vendor/rails/activerecord/lib/active_record/validations.rb:240:in
validate_on_create' ./script/../config/../vendor/rails/activerecord/lib/active_record/validations.rb:379:invalidates_presence_of’
./script/…/config/…/vendor/rails/activerecord/lib/active_record/validations.rb:378:in
validates_presence_of' /home/joe/projects/cisv/trunk/vendor/plugins/login_engine/lib/login_engine/authenticated_user.rb:16:inincluded’
/home/joe/projects/cisv/trunk/vendor/plugins/login_engine/lib/login_engine/authenticated_user.rb:9:in
included' #{RAILS_ROOT}/app/models/user.rb:2 (eval):5:inhas_and_belongs_to_many’
#{RAILS_ROOT}/app/models/training_event.rb:3
(eval):5:in has_and_belongs_to_many' #{RAILS_ROOT}/app/models/user.rb:13 (eval):5:inhas_and_belongs_to_many’
#{RAILS_ROOT}/app/models/training_event.rb:3
(eval):5:in has_and_belongs_to_many' #{RAILS_ROOT}/app/models/user.rb:13 (eval):5:inhas_and_belongs_to_many’

So is this issue still a problem with the latest trunk release?

Anyone know?

I have a Registration that belongs_to a TrainingEvent. TrainingEvent
has_many Registrations.

The tests work as expected. I’m using edge rails, just svn updated.

But when I load it in a web browser, I get:

SystemStackError in #

stack level too deep

RAILS_ROOT: script/…/config/…

./script/…/config/…/vendor/rails/activesupport/lib/active_support/dependencies.rb:26:in
load?' ./script/../config/../vendor/plugins/engines/lib/dependencies_extensions.rb:44:inrequire_or_load’
./script/…/config/…/vendor/rails/activesupport/lib/active_support/dependencies.rb:30:in
depend_on' ./script/../config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:36:inassociate_with’
./script/…/config/…/vendor/rails/activesupport/lib/active_support/dependencies.rb:209:in
require_association' ./script/../config/../vendor/rails/activerecord/lib/active_record/associations.rb:780:inrequire_association_class’
./script/…/config/…/vendor/rails/activerecord/lib/active_record/associations.rb:524:in
belongs_to_without_reflection' (eval):5:inbelongs_to’
#{RAILS_ROOT}/app/models/registration.rb:2
(eval):5:in has_many' #{RAILS_ROOT}/app/models/training_event.rb:3 (eval):5:inbelongs_to’
#{RAILS_ROOT}/app/models/registration.rb:2
(eval):5:in has_many' #{RAILS_ROOT}/app/models/training_event.rb:3 (eval):5:inbelongs_to’
#{RAILS_ROOT}/app/models/registration.rb:2
(eval):5:in has_many' #{RAILS_ROOT}/app/models/training_event.rb:3 (eval):5:inbelongs_to’
#{RAILS_ROOT}/app/models/registration.rb:2
(eval):5:in has_many' #{RAILS_ROOT}/app/models/training_event.rb:3 (eval):5:inbelongs_to’
#{RAILS_ROOT}/app/models/registration.rb:2
(eval):5:in has_many' #{RAILS_ROOT}/app/models/training_event.rb:3 (eval):5:inbelongs_to’
#{RAILS_ROOT}/app/models/registration.rb:2
(eval):5:in `has_many’
#{RAILS_ROOT}/app/models/training_event.rb:3

On 12/1/05, Joe Van D. [email protected] wrote:

Anyone know?

I have a Registration that belongs_to a TrainingEvent. TrainingEvent
has_many Registrations.

Here’s the full application trace. I suspect something’s wonky with
the Engine stuff.

./script/…/config/…/vendor/rails/activesupport/lib/active_support/dependencies.rb:26:in
load?' ./script/../config/../vendor/plugins/engines/lib/dependencies_extensions.rb:44:inrequire_or_load’
./script/…/config/…/vendor/rails/activesupport/lib/active_support/dependencies.rb:30:in
depend_on' ./script/../config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:36:inassociate_with’
./script/…/config/…/vendor/rails/activesupport/lib/active_support/dependencies.rb:209:in
require_association' ./script/../config/../vendor/rails/activerecord/lib/active_record/associations.rb:780:inrequire_association_class’
./script/…/config/…/vendor/rails/activerecord/lib/active_record/associations.rb:524:in
belongs_to_without_reflection' (eval):5:inbelongs_to’
#{RAILS_ROOT}/app/models/registration.rb:2
./script/…/config/…/vendor/rails/activesupport/lib/active_support/dependencies.rb:237:in
load' ./script/../config/../vendor/plugins/engines/lib/dependencies_extensions.rb:45:inrequire_or_load’
./script/…/config/…/vendor/rails/activesupport/lib/active_support/dependencies.rb:30:in
depend_on' ./script/../config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:36:inassociate_with’
./script/…/config/…/vendor/rails/activesupport/lib/active_support/dependencies.rb:209:in
require_association' ./script/../config/../vendor/rails/activerecord/lib/active_record/associations.rb:780:inrequire_association_class’
./script/…/config/…/vendor/rails/activerecord/lib/active_record/associations.rb:355:in
has_many_without_reflection' (eval):5:inhas_many’
#{RAILS_ROOT}/app/models/training_event.rb:3
./script/…/config/…/vendor/rails/activesupport/lib/active_support/dependencies.rb:237:in
load' ./script/../config/../vendor/plugins/engines/lib/dependencies_extensions.rb:45:inrequire_or_load’
./script/…/config/…/vendor/rails/activesupport/lib/active_support/dependencies.rb:30:in
depend_on' ./script/../config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:36:inassociate_with’
./script/…/config/…/vendor/rails/activesupport/lib/active_support/dependencies.rb:209:in
require_association' ./script/../config/../vendor/rails/activerecord/lib/active_record/associations.rb:780:inrequire_association_class’
./script/…/config/…/vendor/rails/activerecord/lib/active_record/associations.rb:524:in
belongs_to_without_reflection' (eval):5:inbelongs_to’
#{RAILS_ROOT}/app/models/registration.rb:2
./script/…/config/…/vendor/rails/activesupport/lib/active_support/dependencies.rb:237:in
load' ./script/../config/../vendor/plugins/engines/lib/dependencies_extensions.rb:45:inrequire_or_load’
./script/…/config/…/vendor/rails/activesupport/lib/active_support/dependencies.rb:30:in
depend_on' ./script/../config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:36:inassociate_with’
./script/…/config/…/vendor/rails/activesupport/lib/active_support/dependencies.rb:209:in
require_association' ./script/../config/../vendor/rails/activerecord/lib/active_record/associations.rb:780:inrequire_association_class’
./script/…/config/…/vendor/rails/activerecord/lib/active_record/associations.rb:355:in
has_many_without_reflection' (eval):5:inhas_many’
#{RAILS_ROOT}/app/models/training_event.rb:3
./script/…/config/…/vendor/rails/activesupport/lib/active_support/dependencies.rb:237:in
load' ./script/../config/../vendor/plugins/engines/lib/dependencies_extensions.rb:45:inrequire_or_load’
./script/…/config/…/vendor/rails/activesupport/lib/active_support/dependencies.rb:30:in
depend_on' ./script/../config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:36:inassociate_with’
./script/…/config/…/vendor/rails/activesupport/lib/active_support/dependencies.rb:209:in
require_association' ./script/../config/../vendor/rails/activerecord/lib/active_record/associations.rb:780:inrequire_association_class’
./script/…/config/…/vendor/rails/activerecord/lib/active_record/associations.rb:524:in
belongs_to_without_reflection' (eval):5:inbelongs_to’

Thanks for finding this, I’ll look into it…

  • james

On 12/2/05, James A. [email protected] wrote:

Thanks for finding this, I’ll look into it…

Why wouldn’t this show up in the tests?

On 12/1/05, Joe Van D. [email protected] wrote:

On 12/1/05, Joe Van D. [email protected] wrote:

Anyone know?

I have a Registration that belongs_to a TrainingEvent. TrainingEvent
has_many Registrations.

Here’s the full application trace. I suspect something’s wonky with
the Engine stuff.

I tried it with 0.14.3 and it’s working fine. So, I think it’s a
problem with Edge rails.

There’s a patch for this now:

http://opensvn.csie.org/rails_engines/branches/edge_engines

  • james

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs