2012-07-24 3 views
1

이 내 기본 클래스sqlalchmey 클래스의 별명?

class Product(Base): 
    __tablename__ = 'PRODUCT' 
    __table_args__ = {'quote':False} 

    ... 
    id = Column(Integer, name='id_prod', primary_key=True) 
    type = Column(String(100),name='id_typ_prod') 

    __mapper_args__ = {'polymorphic_on': type} 

그래서이다, 당연히 우리는이 제품, 예를 들어,에서 확장 클래스의 번호를 가지고 전화 및 케이블, 그들 각각은 자체 테이블에 매핑됩니다.

class Phone (Product): 
    __tablename__ = 'PHONE' 
    ... 

이제 몇 가지 이유로 데이터베이스에 해당 테이블이없는 클래스 인 '별칭'클래스를 만들고 싶습니다. 이런 식으로 뭔가 :

class VapourWare(Product): 
    ... 

내가

class VapourWare(Product): 
    __tablename__ = 'PRODUCT' 
    __mapper_args__ = {'polymorphic_identity':'VapourWare'} 

작동하는 것 같다 않는 경우. 그러나 그것은 옳은가 또는 권장 된 길인가? 나는 여기에 __tablename__ = 'PRODUCT'을 반복하고있다.

답변

1

어느 정도까지는 달성하려는 대상에 따라 다르지만, 예를 들어 SA Docs에서 수행하려는 작업이 Single-Table Inheritence입니다. 연결된 페이지에 나열된 예는 Employee == ProductManager == VapourWare (여기에 Dilbert 농담 삽입)과 같이 매우 유사합니다.