I’ve a question concerning STI in Rails. Let’s say I’ve a Person class
and two classes that inherit from Person: User and Customer. In the DB
I’ve the people table to store both instances of User and Customer.
Now, let’s say I also have Address class, which references a Customer,
and each customer has many addresses. How should I name the relations?
Can it be done in the simple way without specifying column names? If it
can, then what should be the column names?
class Customer < Person
class Address < ActiveRecord::Base
Now, if I call the referencing column in addresses table customer_id, it
won’t find the people table and if I call it person_id, then
Customer.find(:first).addresses will generate bad query, because
addresses table doesn’t have customer_id.
So, should I put all the relations in base class (Person) to make it
work, and just ignore the fact that User doesn’t have addresses? Or is
there any other way to solve it?