1
我有以下型号:如何在继承rails模型时写入不同的表格?
class Building < ActiveRecord::Base;end
class Department < Building;end
class Organization < Building;end
当我创建部门和组织,并得到所有部门
2.1.5 :008 > Department.all.count
(0.5ms) SELECT COUNT(*) FROM "buildings"
=> 2
我想在这种情况下
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
让我怎样才能去做?
继承在rails中创建了一种称为单表继承的功能:http://guides.rubyonrails.org/association_basics.html#single-table-inheritance – Anthony
我认为这不是你想要做的事情。 @Anthony将你带入单表继承(STI) – Sean
的正确轨道,换句话说,当你继承你没有创建多个表时。 –