Forum: Ruby on Rails Circular dependency problem

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.
98872bd7af9f6b8238bfa06d784cf6a7?d=identicon&s=25 Gros Gros (gros)
on 2006-03-01 11:43
Hello,

I use rails 1.0
It seems that i encounter a circular dependency problem, and i can't
manage to solve it.

With the following models

class Customer < ActiveRecord::Base
  has_and_belongs_to_many :projects
end

class Project < ActiveRecord::Base
  has_and_belongs_to_many :customers
end

And a file test.rhtml containg only
<%= Customer.count %>

I get the following error. Can someone explain me why and how to solve
it ?
(P.S.: search is disabled on this forum so maybe it's already explained
somewhere but ... :-))

e:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:207:in
`load'
e:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:207:in
`load'
e:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:39:in
`require_or_load'
e:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:22:in
`depend_on'
e:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:30:in
`associate_with'
e:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:179:in
`require_association'
e:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:179:in
`require_association'
e:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/associations.rb:780:in
`require_association_class'
e:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/associations.rb:650:in
`has_and_belongs_to_many_without_reflection'
(eval):5:in `has_and_belongs_to_many'
#{RAILS_ROOT}/app/models/customer.rb:2
#{RAILS_ROOT}/app/views/search/test.rhtml:1
-e:3:in `load'
-e:3
98872bd7af9f6b8238bfa06d784cf6a7?d=identicon&s=25 Gros Gros (gros)
on 2006-03-01 17:40
help ? :)
This topic is locked and can not be replied to.