Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails STI and the setting of the "type" string

I think I need to use STI in Rails.

Here's my class:

class Person < ActiveRecord::Base
end

class Landlord < Person
end

and the people table has a :type column that's a string.

So, what I expect is to see in the table, is that every row that is a Person has the type set to "Person" and every Landlord has the type set to "Landlord". However, that's not what I see. Each Landlord has the type set to "Landlord", but all the Person have their type set to nil. This very well could be the way that rails works, but I was just looking for some confirmation.

like image 673
TheDelChop Avatar asked Feb 01 '11 01:02

TheDelChop


1 Answers

This is, indeed, how STI works. The base class has a type of NULL in the database (or nil in ruby).

like image 57
Jeff Paquette Avatar answered Oct 01 '22 03:10

Jeff Paquette