This project is archived and is in readonly mode.

#91 ✓resolved
Ian Ownbey

STI sub classes not loaded until parent is

Reported by Ian Ownbey | May 2nd, 2008 @ 01:23 AM

When using STI, a Uninitialised Constant error is thrown when calling subclasses (Doc in following example) before parent class is called (container in following example).

Ex:

class Container < ActiveRecord::Base
end

class Doc < Container
end

Doc
#=> uninitialized constant Doc
Container
#=> Okay
Doc
#=> Okay

Comments and changes to this ticket

  • Frederick Cheung

    Frederick Cheung May 2nd, 2008 @ 02:28 AM

    Works fine for me. Where have you put these classes?

  • Ian Ownbey

    Ian Ownbey May 2nd, 2008 @ 02:51 AM

    ooooo all the STI are in the same file as the model. This could be creating the problem.

  • Frederick Cheung

    Frederick Cheung May 2nd, 2008 @ 09:58 AM

    That will definitely be a problem. If they are both in container.rb, how can the dependencies mechanism know that if you hit const_missing for Doc you need to look in container.rb?

  • DHH

    DHH May 3rd, 2008 @ 05:03 PM

    • State changed from “new” to “resolved”

    Auto-loading only works when each class is in its own file. If you want to keep all the files in one, you can always force the load with require_dependency 'container' some where.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages