示例#1
0
class Answer(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    question_id = db.Column(db.Integer, db.ForeignKey('question.id', ondelete='CASCADE'))
    question = db.relationship('Question', backref=db.backref('answer_set'))
    content = db.Column(db.Text(), nullable=False)
    create_date = db.Column(db.DateTime(), nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id', ondelete='CASCADE'), nullable=False)
    user = db.relationship('User', backref=db.backref('answer_set'))
示例#2
0
class Answer(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    # ForeignKey(외래값)는 다른 데이터테이블의 primary_key(고유값)를 사용하는 것
    # ondelete='CASCADE'는 answer에서 삭제되었을때 question에서도 삭제하는 것
    question_id = db.Column(db.Integer, db.ForeignKey('question.id', ondelete='CASCADE'))
    question = db.relationship('Question', backref=db.backref('answer_set'))
    content = db.Column(db.Text(), nullable=False)
    create_date = db.Column(db.DateTime(), nullable=False)
    # 컬럼 추가
    user_id = db.Column(db.Integer, db.ForeignKey('user.id', ondelete='CASCADE'), nullable=False)
    user = db.relationship('User', backref=db.backref('answer_set'))
    modify_date = db.Column(db.DateTime(), nullable=True)
示例#3
0
class Question(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    subject = db.Column(db.String(200), nullable=False)
    content = db.Column(db.Text(), nullable=False)
    create_date = db.Column(db.DateTime(), nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id', ondelete='CASCADE'), nullable=False)
    user = db.relationship('User', backref=db.backref('question_set'))
class Answer(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    # Question 모델의 primary key / 질문 삭제시 함께 삭제
    question_id = db.Column(db.Integer,
                            db.ForeignKey('question.id', ondelete='CASCADE'))
    # 답변 모델에서 질문 모델 참조 / 역참조 설정, 질문 삭제시 함께 삭제
    question = db.relationship('Question',
                               backref=db.backref(
                                   'answer_set', cascade='all, delete-orphan'))
    content = db.Column(db.Text(), nullable=False)
    create_date = db.Column(db.DateTime(), nullable=False)