Search code examples
python-3.xpostgresqlsqlalchemycascading-deletes

SQL Alchemy - delete orphan from multiple one to one relationships on one entity


I got defined on one table these two one to one relationships.

    home_lineup_id = Column(Integer, ForeignKey("Lineup.id"))
    home_lineup = relationship("Lineup", foreign_keys=[home_lineup_id], cascade="all, delete-orphan", single_parent=True)
    guest_lineup_id = Column(Integer, ForeignKey("Lineup.id"))
    guest_lineup = relationship("Lineup", foreign_keys=[guest_lineup_id], cascade="all, delete-orphan", single_parent=True)

And quite obviously I´d like the delete orphan fuctionality to work. This solution rather oddly deletes only half the Lineups presumably ones from the first relationship.

Is there any way to achieve this?

Edit: I´m using PostgreSQL.


Solution

  • Turns out this code is completely fine and works as intended. It was just a typo elsewhere.