Answer the question
In order to leave comments, you need to log in
Multiple Many2One relationships in SQLAlchemy?
class Person(BaseTable):
__tablename__ = "persons"
id = Column(Integer, primary_key=True)
class F(BaseTable):
__tablename__ = "fabcs"
abc_id = Column(Integer, ForeignKey("persons.id"))
a = relationship('Person')
b = relationship('Person')
c = relationship('Person')
Answer the question
In order to leave comments, you need to log in
Understood it. The casket just opened:
docs.sqlalchemy.org/en/rel_1_0/orm/join_conditions.html
In this case, it will look like this:
class F(BaseTable):
__tablename__ = "fabcs"
a_id = Column(Integer, ForeignKey("persons.id"))
b_id = Column(Integer, ForeignKey("persons.id"))
c_id = Column(Integer, ForeignKey("persons.id"))
a = relationship('Person', foreign_keys=[a_id])
b = relationship('Person', foreign_keys=[b_id])
c = relationship('Person', foreign_keys=[c_id])
from documentation :
class Parent(Base):
__tablename__ = 'parent'
id = Column(Integer, primary_key=True)
children = relationship("Child")
class Child(Base):
__tablename__ = 'child'
id = Column(Integer, primary_key=True)
parent_id = Column(Integer, ForeignKey('parent.id'))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question