| 877 | @testing.fixture() |
| 878 | def run_test(self): |
| 879 | def go(CommonMixin): |
| 880 | declarative = registry().mapped |
| 881 | |
| 882 | @declarative |
| 883 | @dataclasses.dataclass |
| 884 | class BaseType(CommonMixin): |
| 885 | discriminator = Column("type", String(50)) |
| 886 | __mapper_args__ = dict(polymorphic_on=discriminator) |
| 887 | id = Column(Integer, primary_key=True) |
| 888 | value = Column(Integer()) |
| 889 | |
| 890 | @declarative |
| 891 | @dataclasses.dataclass |
| 892 | class Single(BaseType): |
| 893 | __tablename__ = None |
| 894 | __mapper_args__ = dict(polymorphic_identity="type1") |
| 895 | |
| 896 | @declarative |
| 897 | @dataclasses.dataclass |
| 898 | class Joined(BaseType): |
| 899 | __mapper_args__ = dict(polymorphic_identity="type2") |
| 900 | id = Column( |
| 901 | Integer, ForeignKey("basetype.id"), primary_key=True |
| 902 | ) |
| 903 | |
| 904 | eq_(BaseType.__table__.name, "basetype") |
| 905 | eq_( |
| 906 | list(BaseType.__table__.c.keys()), |
| 907 | ["type", "id", "value", "timestamp"], |
| 908 | ) |
| 909 | eq_(BaseType.__table__.kwargs, {"mysql_engine": "InnoDB"}) |
| 910 | assert Single.__table__ is BaseType.__table__ |
| 911 | eq_(Joined.__table__.name, "joined") |
| 912 | eq_(list(Joined.__table__.c.keys()), ["id"]) |
| 913 | eq_(Joined.__table__.kwargs, {"mysql_engine": "InnoDB"}) |
| 914 | |
| 915 | yield go |
| 916 | |