원하는 테이블끼리 직접적인 릴레이션이 없을 때, 한단계 거쳐서 가져와야할 때 사용.
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)
docs.sqlalchemy.org/en/14/orm/join_conditions.html#composite-secondary-joins
'개발 > 파이썬' 카테고리의 다른 글
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 |
댓글