2
我試圖實現一個像這樣的結構:GrandFather < - 父< - 子 使用rails和gem citier。這個例子應該創建2個表來表示3個類:一個用於Root類(GrandFather),另一個用於表示父類和子類(因爲Son沒有附加屬性)和父屬性。Rails - Citier - 兩級繼承,子類不繼承中間類屬性
class GrandFather < ActiveRecord::Base
acts_as_citier
attr_accessible :grand_father_attr, :type
end
class Father < GrandFather
acts_as_citier
attr_accessible :father_attr
end
class Son < Father
end
class CreateGrandFathers < ActiveRecord::Migration
def change
create_table :grand_fathers do |t|
t.string :type
t.string :grand_father_attr
t.timestamps
end
end
end
class CreateFathers < ActiveRecord::Migration
def up
create_table :fathers do |t|
t.string :father_attr
end
create_citier_view(Father)
end
def down
drop_citier_view(Father)
drop_table :fathers
end
end
但是,如果我打開軌道控制檯,輸入「Son.new」從爺爺的屬性是存在的,但是從父類中的一個缺失:
1.9.3-p362 :001 > Son.new
citier -> Root Class
citier -> table_name -> grand_fathers
citier -> Non Root Class
citier -> table_name -> fathers
citier -> tablename (view) -> view_fathers
(1.1ms) SELECT COUNT(*)
FROM pg_tables
WHERE tablename = 'grand_fathers'
(0.5ms) SELECT COUNT(*)
FROM pg_views
WHERE viewname = 'grand_fathers'
=> #<Son id: nil, type: "Son", grand_father_attr: nil, created_at: nil, updated_at: nil>