""" Cross-model relationships. This module defines relationships that reference models from other model files (e.g., DecklistFile.card_links → DeckCardLink). These must be defined AFTER all model classes have been imported to avoid circular import issues. Import this module LAST in app/models/__init__.py. """ from sqlalchemy.orm import relationship from app.models.models import DecklistFile from app.models.mirror_models import DeckCardLink # Add the back-reference from DecklistFile to DeckCardLink. # This was previously defined dynamically at the bottom of mirror_models.py, # but that caused circular imports. Now it lives here and is imported last. DecklistFile.card_links = relationship( "DeckCardLink", back_populates="deck", cascade="all, delete-orphan", order_by="DeckCardLink.id" )