Forum: Ruby on Rails Single table inheritance and sub classes in subdirectories.

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.
19c055c52e6f7b217c82612634685ce8?d=identicon&s=25 Guardia Alata (Guest)
on 2007-02-14 12:44
(Received via mailing list)
Hi everyone,

I'm trying to organize my sources, according to the new 1.2

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
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?

A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (au5lander)
on 2007-02-14 14:01
(Received via mailing list)
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


class Dog
This topic is locked and can not be replied to.