1
我想要一個基礎實體,其中的字段deleted
標記爲已刪除的記錄。我有2子類,他們每個人都有自己的表,所有自己列:帶有具體繼承的基礎實體
from elixir import *
from sqlalchemy import create_engine
class Catalog(Entity):
using_options(inheritance='concrete')
deleted = Boolean
class Contact(Catalog):
using_options(inheritance='concrete')
name = Field(String(60))
class Location(Catalog):
using_options(inheritance='concrete')
name = Field(String(100))
setup_all()
metadata.bind = create_engine('sqlite:///', echo=True)
metadata.create_all()
而結果:
CREATE TABLE __main___catalog (
id INTEGER NOT NULL,
PRIMARY KEY (id)
)
CREATE TABLE __main___contact (
id INTEGER NOT NULL,
name VARCHAR(60),
PRIMARY KEY (id)
)
CREATE TABLE __main___location (
id INTEGER NOT NULL,
name VARCHAR(100),
PRIMARY KEY (id)
)
問題:
如何避免創建一個表的基地實體?- 解決:using_options(abstract = True)
爲什麼字段- 這解決了 - 我忘了把它放在一個deleted
不在創建的表中?Field
- 我想避免在每個子類
using_options(inheritance='concrete')
鍵入,但仍然有「具體繼承」。有沒有辦法讓所有的子類都成爲默認的?