원하는 테이블끼리 직접적인 릴레이션이 없을 때, 한단계 거쳐서 가져와야할 때 사용.
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
'개발 > 파이썬' 카테고리의 다른 글
Google Drive에서 파일을 받으려는데 The requested conversion is not supported가 난다면 (0) | 2021.01.30 |
---|---|
Compute engine (우분투 18.04 LTS)에 파이썬 설치 (0) | 2020.12.31 |
Flask-SQLAlchemy의 Column에 subquery 사용 (0) | 2020.12.21 |
Python으로 http 서버 띄우기 (0) | 2020.12.16 |
파라메터를 정의하는 새로운 방법 (0) | 2020.12.07 |
댓글