sqlalchemy:relationship将复制与关系冲突的列

ddarikpa  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(338)

我有以下Map

class Socio(Base):
    __tablename__ = "socio"
    member_id = Column(Integer, primary_key=True)
    work_profile = relationship(
        "Laboral",
        uselist=False,
        primaryjoin="foreign(Socio.member_id) == Laboral.member_id",
    )

class Familiar(Base):
    __tablename__ = "familiar"
    member_id = Column(Integer, ForeignKey("socio.member_id"), primary_key=True)
    family_code = Column(Integer, primary_key=True)
    socio = relationship("Socio", backref="familiares")
    work_profile = relationship(
        "Laboral",
        uselist=False,
        primaryjoin="and_("
        "foreign(Familiar.member_id) == Laboral.member_id, "
        "foreign(Familiar.family_code) == Laboral.family_code"
        ")",
    )

class Laboral(Base):
    member_id = Column(Integer, ForeignKey("socio.member_id"), primary_key=True)
    family_code = Column(Integer, primary_key=True)
    __tablename__ = "laboral"
    __table_args__ = (
        ForeignKeyConstraint(
            ("member_id", "family_code"), ("familiar.member_id", "familiar.family_code")
        ),
    )

在尝试对Social或Friends执行查询时,我收到以下警告:

SAWarning: relationship 'Familiar.work_profile' will copy column laboral.member_id to 
column familiar.member_id, which conflicts with relationship(s): 'Familiar.socio' (copies
 socio.member_id to familiar.member_id), 'Socio.familiares' (copies socio.member_id to 
familiar.member_id). If this is not the intention, consider if these relationships should
 be linked with back_populates, or if viewonly=True should be applied to one or more if 
they are read-only. For the less common case that foreign key constraints are partially 
overlapping, the orm.foreign() annotation can be used to isolate the columns that should 
be written towards.   To silence this warning, add the parameter 
'overlaps="familiares,socio"' to the 'Familiar.work_profile' relationship.

我有点新使用sqlalchemy进行dbMap,我更习惯于django orm的魔力。
如何解决此警告并纠正所有关系?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题