我试图定义一个SQLAlchemy/Elixer模型,它可以描述以下关系。我有一个SSP表,它有多个POC表的外键。我已经在SSP对象中正确定义了多通关系(允许我
SSP.get(1).action.first_name
正确)。我还想补充的是这种关系的另一面,在那里我可以执行类似的操作
POC.get(1).csa
并返回其中此POC定义为idPOCCSA的SSP对象列表。
我知道这对多态关联来说是最好的,但我真的根本无法更改DB模式(创建一个新的poc2ssp表,其中包含一列
type
(协会的成员)。
class POC(Entity):
using_options(tablename = 'poc', autoload = True)
# These two line visually display my "issue":
# csa = OneToMany('SSP')
# action = OneToMany('SSP')
class SSP(Entity):
'''
Many to One Relationships:
- csa: ssp.idPOCCSA = poc.id
- action: ssp.idPOCAction = poc.id
- super: ssp.idSuper = poc.id
'''
using_options(tablename = 'spp', autoload = True)
csa = ManyToOne('POC', colname = 'idPOCCSA')
action = ManyToOne('POC', colname = 'idPOCAction')
super = ManyToOne('POC', colname = 'idPOCSuper')