Python 具有具体继承的基础实体
我希望有一个带有字段Python 具有具体继承的基础实体,python,sqlalchemy,python-elixir,Python,Sqlalchemy,Python Elixir,我希望有一个带有字段deleted的基本实体,该字段标记已删除的记录。我有2个子类,每个子类都有自己的表和所有列: from elixir import * from sqlalchemy import create_engine class Catalog(Entity): using_options(inheritance='concrete') deleted = Boolean class Contact(Catalog): using_options(in
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)
)
问题:
使用_选项(abstract=True)
已删除
不在创建的表中?-这个问题解决了-我忘了把它放在字段中
中键入内容,但仍然有“concrete heritation”。有没有一种方法可以使它成为所有子类的默认值
class Catalog(Entity):
deleted = Field(Boolean)
using_options(abstract = True, inheritance = 'concrete')
class Contact(Catalog):
name = Field(String(60))
class Location(Catalog):
name = Field(String(100))
并创建以下表:
CREATE TABLE __main___contact (
id INTEGER NOT NULL,
deleted BOOLEAN,
name VARCHAR(60),
PRIMARY KEY (id),
CHECK (deleted IN (0, 1))
)
CREATE TABLE __main___location (
id INTEGER NOT NULL,
deleted BOOLEAN,
name VARCHAR(100),
PRIMARY KEY (id),
CHECK (deleted IN (0, 1))
)