# Single table inheritance and sub classes in subdirectories

**URL:** <https://www.ruby-forum.com/t/single-table-inheritance-and-sub-classes-in-subdirectories/85541>\
**Category:** Rails\
**Created:** [February 14, 2007, 12:44pm UTC](https://www.ruby-forum.com/t/single-table-inheritance-and-sub-classes-in-subdirectories/85541 "2007-02-14T12:44:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guardia\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f05b48/32.png) [@Guardia\_A](https://www.ruby-forum.com/u/Guardia_A)\
**Post date:** [February 14, 2007, 12:44pm UTC](https://www.ruby-forum.com/t/single-table-inheritance-and-sub-classes-in-subdirectories/85541/1 "2007-02-14T12:44:16Z")

</div>

Hi everyone,

I’m trying to organize my sources, according to the new 1.2  
specifications.

So, i’ve an Animal class, with some subclasses (Dog,Bird,Snake).

Animal is in /model, the others in /models/animals.

When i’ve to instantiate a Dog, doing something like Animals::Dog.new  
i’ve an exception:

The single-table inheritance mechanism failed to locate the  
subclass: ‘Dog’. This error is raised because the column ‘type’ is  
reserved for storing the class in case of inheritance. (cut)

This occurs why Rails is going to write just “Dog” in the type  
column, and not “Animals::Dog”, so in the next call to the object the  
operation fails.

I’m doing something messy or it’s just an issue?

Thanks,  
alessio.

---

<div class="post-metadata">

**Author:** ![Guardia\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f05b48/32.png) [@Guardia\_A](https://www.ruby-forum.com/u/Guardia_A)\
**Post date:** [February 14, 2007, 2:01pm UTC](https://www.ruby-forum.com/t/single-table-inheritance-and-sub-classes-in-subdirectories/85541/2 "2007-02-14T14:01:22Z")

</div>

I looked in trac to see if there was a ticket for this and I couldn’t  
find one, although that doesn’t necessarily mean one doesn’t exist.

If I were you, I would check out trac more thoroughly and if you can’t  
find anything related to it, open a ticket. be sure to include a  
test. My guess is that demodulize is getting called on the class name  
when it shouldn’t be.

Also, if you were to replace the type from ‘Dog’ to ‘Animals::Dog’ in  
the database, it loads the record just fine.

in the meantime, i would just put all your animal models in your main  
app/models directory, and change the class definitions from

class Animals::Dog \< Animal  
end

to

class Dog  
end
