jeudi 23 février 2017

How to write into different tables when rails model has been inherited?

I have next models

class Building < ActiveRecord::Base;end

class Department < Building;end

class Organization < Building;end

When I create department and organization and get all departments

2.1.5 :008 > Department.all.count
(0.5ms)  SELECT COUNT(*) FROM "buildings"
=> 2 

I would like to get in this case

2.1.5 :008 > Department.all.count
(0.5ms)  SELECT COUNT(*) FROM "departments"
=> 1 

2.1.5 :008 > Organization.all.count
(0.5ms)  SELECT COUNT(*) FROM "organizations"
=> 1

2.1.5 :008 > Buildings.all.count
(0.5ms)  SELECT COUNT(*) FROM "buildings"
=> 2 

How I can do that?

Aucun commentaire:

Enregistrer un commentaire