Rails STI and type string customization

I think I need to use STI in Rails.

Here is my class:

class Person < ActiveRecord::Base end class Landlord < Person end 

and the people table has a :type column that contains a row.

So, I expect to see in the table that each row that is a Person has a type defined as “Person”, and each Landlord has a type specified by “Landlord”. However, this is not what I see. Each Landlord has a type set to "Landlord", but each Person has its own type, equal to zero. It is very good that the rails work, but I was just looking for confirmation.

+4
source share
2 answers

This is really how the STI works. The base class is NULL in the database (or nil in ruby).

+11
source

You can solve this problem if you want by adding a type column with the default value of "Person" .

+5
source

Source: https://habr.com/ru/post/1337886/


All Articles