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?
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to