Flask-SQLAlchemy에서 secondaryjoin
원하는 테이블끼리 직접적인 릴레이션이 없을 때, 한단계 거쳐서 가져와야할 때 사용.
class User(db.Model):
....
class Question(db.Model):
...
users = db.relationship('User', secondary='answer', backref='answer.uid')
class Answer(db.Model):
uid = db.Column(db.String(36), db.ForeignKey('user.id', ondelete="CASCADE"), nullable=False)
qid = db.Column(db.String(36), db.ForeignKey('question.id', ondelete="CASCADE"), nullable=False)
How do 'primaryjoin' and 'secondaryjoin' work for many-to-many relationship in SQLAlchemy?
Having some difficulty understanding some Flask-SQLAlchemy stuff from the Flask Mega Tutorial. Here's the code: followers = db.Table('followers', db.Column('follower_id', db.Integer, db.Foreig...
stackoverflow.com
docs.sqlalchemy.org/en/14/orm/join_conditions.html#composite-secondary-joins
Configuring how Relationship Joins — SQLAlchemy 1.4 Documentation
relationship() will normally create a join between two tables by examining the foreign key relationship between the two tables to determine which columns should be compared. There are a variety of situations where this behavior needs to be customized. Spec
docs.sqlalchemy.org