I have a bug concerning ActiveRecord. It cannot find a method in my ActiveRecord ORM mapping. I have the following. Given two mysql-database tables in one-to-many association:
1.) Country
class Db::Country < ActiveRecord::Base
has_many :regions
end
2.) Region
class Db::Region < ActiveRecord::Base
has_many :cities
belongs_to :country
end
I have a class ../app/managers/location_manager.rb and one of the method is:
def get_cities_by_country( country, language )
# check whether countries and regions firstly need to be retrieved from web service
get_countries_and_regions [[BR]]
coun = Country.find(:first, :conditions => "isoCode='#{country}'") [[BR]]
puts coun.methods.sort // line 270 [[BR]]
reg = coun.regions // line 271 [[BR]]
...
end
This method shall get called by search method in the class ../app/controllers/inform_controller.rb:
def index [[BR]]
search [[BR]]end
def search
... [[BR]]
@locMan = LocationManager.new [[BR]]
# get all French countries in German [[BR]]
@cities = @locMan.get_cities_by_country('FR', 'DE') [[BR]]
... [[BR]]
end
The problem is as follows: My web page invokes the "index" method of the "inform_controller", this goes to the "search" method, and this goes to the "get_cities_by_country" method of the "location_manager". When I first load my web page no error occurrs and every successive loading of my web page results in the following error:
undefined method `regions' for #<Db::Country:0x10945610>
RAILS_ROOT: script/../config/..
Application Trace | Framework Trace | Full Trace [[BR]]
./script/../config/../vendor/rails/activerecord/lib/active_record/base.rb:1497:in `method_missing'[[BR]]
./script/../config/../app/managers/location_manager.rb:271:in `get_cities_by_country' [[BR]]
./script/../config/../app/controllers/inform_controller.rb:24:in `search' [[BR]]
./script/../config/../app/controllers/inform_controller.rb:4:in `index' [[BR]]
And it seems it is a bug in the ActiveRecord and as shown by line 270, indeed it does not list the method regions, regions= at the second, third, ... time of loading my web page.
Ruby version: ruby 1.8.3 (2005-09-21) [i386-cygwin]
Rails version: Rails 0.14.1
Updated by svn trunk in repository.
Help would be highly appreciated! I also will add further information about the error if requested as the account of discussion may not be detailed enough.