I'm trying using STI to implement a hiearchy similar to this:
script/generate scaffold name:string type:string
class Person < ActiveRecord::Base; end class Customer < Person; end class Employee < Person; end class Developer < Employee; end
I.e., there are two levels of inheritance (Developer < Employee < Person).
When creating a Customer, Rails understands it's a Person, but if I create a Developer, Rails 'tends to forget' it's an Employee. In other words:
$ script/console
Developer.create :name=>'Bob'
=> #<Developer id: 1, name: "Bob", type: "Developer", created_at: "2009-05-08 09:59:58", updated_at: "2009-05-08 09:59:58">
exit
$ script/console
Employee.find :all
=>
Person.find :all
=> [#<Developer id: 1, name: "Bob", type: "Developer", created_at: "2009-05-08 09:59:58", updated_at: "2009-05-08 09:59:58">]
Worst of all, if I change the order of the 'find' statements, things work:
$ script/console
Person.find :all
=> [#<Developer id: 1, name: "Bob", type: "Developer", created_at: "2009-05-08 09:59:58", updated_at: "2009-05-08 09:59:58">]
Employee.find :all
=> [#<Developer id: 1, name: "Bob", type: "Developer", created_at: "2009-05-08 09:59:58", updated_at: "2009-05-08 09:59:58">]
Maybe this has to do with some caching stuff... any ideas?