我想要一个带有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')
,但仍然有“具体继承”。有没有办法让它默认所有子类?