Skip to content
Discussion options

You must be logged in to vote

If we use a Session and flush it after adding ORM objects, it seems to work as far as I can tell:

from sqlalchemy import Column, ForeignKey, Integer, String
from sqlalchemy.orm import DeclarativeBase, relationship


class Base(DeclarativeBase):
    pass


class Parent(Base):
    __tablename__ = "parent_table"
    id = Column(Integer, primary_key=True)
    name = Column(String)
    children = relationship(
        "Child",
        primaryjoin="or_(Parent.id == Child.father_id, Parent.id == Child.mother_id)",
        viewonly=True,
    )


class Child(Base):
    __tablename__ = "child_table"
    id = Column(Integer, primary_key=True)
    name = Column(String)
    mother_id = Column(Integer, F…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@dlax
Comment options

Answer selected by madduck
@madduck
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants