I a modeling Users in my rails app
Student < User
Parent < User
Staff < User
User
Every entity has slightly different attributes. I was going to use STI but thinking there might be a better way to model this e.g. originally i had
User
--------
id #primary key
name #common
email #common
type [Student|Parent|Staff]
id # Student only
school # Student only
year # Student only
title # Parent only
work # Parent only
i.e Instead I wanted to split this into multiple tables, A User table with all users, then joining via natural keys into user specific tables. Was planning to use NATURAL JOINS e.g. DB would look like
User
--------
id
name
email
type [Student|Parent|Staff]
Student
--------
id
school
year
Parent
-------
title
work
So how do I get active record to do a Natural Join of Student and User table
i.e. I want to be able to do something like
class Student < ActiveRecord::Base
end
# would create an entry in Student and User tables.
Student.create(name:'john',school:'green high')
# get via field in User table and puts out field in Student table
student = Student.where(email:'a@a.com')
puts student.school
Kinda look for something like http://viralpatel.net/blogs/hibernate-inheritance-table-per-concrete-class-annotation-xml-mapping/
P.S I am about to upgrade to Rails 4 if that makes a difference in syntax would like to know if there is any changes in rails 4 vs rails 3 for this kind of thing.