Forum: Ruby on Rails has_and_belongs_to_many question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
38a8230ed3d5c685558b4f0aad3fc74b?d=identicon&s=25 joevandyk (Guest)
on 2005-11-26 18:39
(Received via mailing list)
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:in
`write_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:in
`validates_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:in
`included'
/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:in `has_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:in `has_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:in `has_and_belongs_to_many'
#{RAILS_ROOT}/app/models/training_event.rb:
38a8230ed3d5c685558b4f0aad3fc74b?d=identicon&s=25 joevandyk (Guest)
on 2005-11-26 20:40
(Received via mailing list)
Can I clarify this question somehow?
38a8230ed3d5c685558b4f0aad3fc74b?d=identicon&s=25 joevandyk (Guest)
on 2005-11-27 23:24
(Received via mailing list)
On 11/26/05, Joe Van Dyk <joevandyk@gmail.com> 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 <controller not set>#<action not set>

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:in
`singularize'
./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:in
`has_many_without_reflection'
(eval):5:in `has_many'
#{RAILS_ROOT}/app/models/chapter.rb:2
(eval):5:in `belongs_to'
#{RAILS_ROOT}/app/models/training_event.rb:4
(eval):5:in `has_many'
#{RAILS_ROOT}/app/models/chapter.rb:2
(eval):5:in `belongs_to'
#{RAILS_ROOT}/app/models/training_event.rb:4
(eval):5:in `has_many'
#{RAILS_ROOT}/app/models/chapter.rb:2
(eval):5:in `belongs_to'
#{RAILS_ROOT}/app/models/training_event.rb:4
(eval):5:in `has_many'
#{RAILS_ROOT}/app/models/chapter.rb:2
(eval):5:in `belongs_to'
#{RAILS_ROOT}/app/models/training_event.rb:4
(eval):5:in `has_many'
#{RAILS_ROOT}/app/models/chapter.rb:2
(eval):5:in `belongs_to'
38a8230ed3d5c685558b4f0aad3fc74b?d=identicon&s=25 joevandyk (Guest)
on 2005-11-27 23:28
(Received via mailing list)
On 11/27/05, Joe Van Dyk <joevandyk@gmail.com> 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 <controller not set>#<action not set>

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:in
`write_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:in
`validates_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:in
`included'
/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:in `has_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:in `has_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:in `has_and_belongs_to_many'
3dd4b52a0946bd698b1d1635a46ea3a3?d=identicon&s=25 francois.beausoleil (Guest)
on 2005-11-28 16:50
(Received via mailing list)
Hi !

2005/11/27, Joe Van Dyk <joevandyk@gmail.com>:
>  SystemStackError in <controller not set>#<action not set>

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 !
38a8230ed3d5c685558b4f0aad3fc74b?d=identicon&s=25 joevandyk (Guest)
on 2005-11-28 19:28
(Received via mailing list)
Ah, thank you.  That may have been it.
38a8230ed3d5c685558b4f0aad3fc74b?d=identicon&s=25 joevandyk (Guest)
on 2005-11-28 22:34
(Received via mailing list)
So is this issue still a problem with the latest trunk release?
38a8230ed3d5c685558b4f0aad3fc74b?d=identicon&s=25 joevandyk (Guest)
on 2005-12-02 04:07
(Received via mailing list)
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 <controller not set>#<action not set>

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:in
`require_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:in
`associate_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:in
`require_association_class'
./script/../config/../vendor/rails/activerecord/lib/active_record/associations.rb:524:in
`belongs_to_without_reflection'
(eval):5:in `belongs_to'
#{RAILS_ROOT}/app/models/registration.rb:2
(eval):5:in `has_many'
#{RAILS_ROOT}/app/models/training_event.rb:3
(eval):5:in `belongs_to'
#{RAILS_ROOT}/app/models/registration.rb:2
(eval):5:in `has_many'
#{RAILS_ROOT}/app/models/training_event.rb:3
(eval):5:in `belongs_to'
#{RAILS_ROOT}/app/models/registration.rb:2
(eval):5:in `has_many'
#{RAILS_ROOT}/app/models/training_event.rb:3
(eval):5:in `belongs_to'
#{RAILS_ROOT}/app/models/registration.rb:2
(eval):5:in `has_many'
#{RAILS_ROOT}/app/models/training_event.rb:3
(eval):5:in `belongs_to'
#{RAILS_ROOT}/app/models/registration.rb:2
(eval):5:in `has_many'
#{RAILS_ROOT}/app/models/training_event.rb:3
(eval):5:in `belongs_to'
#{RAILS_ROOT}/app/models/registration.rb:2
(eval):5:in `has_many'
#{RAILS_ROOT}/app/models/training_event.rb:3
38a8230ed3d5c685558b4f0aad3fc74b?d=identicon&s=25 joevandyk (Guest)
on 2005-12-02 04:19
(Received via mailing list)
On 12/1/05, Joe Van Dyk <joevandyk@gmail.com> 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:in
`require_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:in
`associate_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:in
`require_association_class'
./script/../config/../vendor/rails/activerecord/lib/active_record/associations.rb:524:in
`belongs_to_without_reflection'
(eval):5:in `belongs_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:in
`require_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:in
`associate_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:in
`require_association_class'
./script/../config/../vendor/rails/activerecord/lib/active_record/associations.rb:355:in
`has_many_without_reflection'
(eval):5:in `has_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:in
`require_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:in
`associate_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:in
`require_association_class'
./script/../config/../vendor/rails/activerecord/lib/active_record/associations.rb:524:in
`belongs_to_without_reflection'
(eval):5:in `belongs_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:in
`require_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:in
`associate_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:in
`require_association_class'
./script/../config/../vendor/rails/activerecord/lib/active_record/associations.rb:355:in
`has_many_without_reflection'
(eval):5:in `has_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:in
`require_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:in
`associate_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:in
`require_association_class'
./script/../config/../vendor/rails/activerecord/lib/active_record/associations.rb:524:in
`belongs_to_without_reflection'
(eval):5:in `belongs_to'
38a8230ed3d5c685558b4f0aad3fc74b?d=identicon&s=25 joevandyk (Guest)
on 2005-12-02 04:31
(Received via mailing list)
On 12/1/05, Joe Van Dyk <joevandyk@gmail.com> wrote:
> On 12/1/05, Joe Van Dyk <joevandyk@gmail.com> 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.
05d703f649ef1d07e78d7b479fb4c4ac?d=identicon&s=25 james.adam (Guest)
on 2005-12-02 10:41
(Received via mailing list)
Thanks for finding this, I'll look into it...

- james
38a8230ed3d5c685558b4f0aad3fc74b?d=identicon&s=25 joevandyk (Guest)
on 2005-12-02 19:14
(Received via mailing list)
On 12/2/05, James Adam <james.adam@gmail.com> wrote:
> Thanks for finding this, I'll look into it...

Why wouldn't this show up in the tests?
05d703f649ef1d07e78d7b479fb4c4ac?d=identicon&s=25 james.adam (Guest)
on 2005-12-05 13:39
(Received via mailing list)
There's a patch for this now:

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

- james
This topic is locked and can not be replied to.