Forum: Ruby on Rails When does Rails remove 'association' methods?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
05748a61a1b05130ec508434301aecf1?d=identicon&s=25 Lee (Guest)
on 2007-01-09 03:59
(Received via mailing list)
My tests indicate that, when running in development mode, Rails removes
'association' methods (e.g. a method created for has_many) after the
processing of a request completes. I assume they are removed from the
class object for the given instance object.

For example, my code is as follows:

class Picklist < ActiveRecord::Base

  has_many :list_items

class ListItems < ActiveRecord::Base

  belongs_to :picklist

I also have a singleton factory class called 'PicklistFactory' which
allows me to:

picklist=PicklistFactory.create.get_picklist(<type of picklist

This returns me an object of class Picklist.

The idea is that the factory object is created once only and will
return Picklist objects on-demand. The create method checks if an
object exists and if so returns it, otherwise creates an object
containing all available Picklist objects in the database.

I observe that the factory object and its referenced Picklist objects
'stay around' between HTTP requests but the association method
list_items is not available for subsequent requests and throws an
method_missing error.

I'd like to understand why the association method disappears and
whether this would be the case in production (require-mode).

Any pointers/thoughts appreciated.
This topic is locked and can not be replied to.