在两个孩子之间的公共列中添加与辅助关系

时间:2019-07-29 17:38:59

标签: python sqlalchemy

我遇到的情况与以下情况相似

CREATE TABLE common_parent (
    parent_id,
    other_cols
)

CREATE TABLE child_one (
    child_one_id,
    parent_id,
    common_attribute,
    other_cols
)

CREATE TABLE child_two (
    child_two_id,
    parent_id,
    other_cols
)

CREATE TABLE child_two_child (
    child_two_child_id,
    child_two_id,
    common_attribute,
    other_cols
)

我正在向child_one orm添加关系。我与根据child_two匹配(给出返回对象的列表)而定义的parent_id有关系

child_twos = relationship('ChildTwo', uselist=True)

我要做什么:在child_two_child的附加限制下向common_attribute添加关系

child_two_children = relationship('ChildTwoChild', secondary='ChildTwo', uselist=True)

这有效并给出了结果,但是它没有应用child_one.common_attribute == child_two_child.common_attribute的附加限制。如何更改以上内容以实现此目的? (我无法更改DDL,因为它已经存在旧设计)

0 个答案:

没有答案