Answer the question
In order to leave comments, you need to log in
How to do a left outer join using flask-sqlalchemy?
There are three tables:
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
score = db.Column(db.Integer, nullable=False, default=0)
results = db.relationship('Result', backref='solver', lazy='dynamic')
class Riddle(db.Model):
id = db.Column(db.Integer, primary_key=True)
text = db.Column(db.String, unique=True, nullable=False)
answer = db.Column(db.String, nullable=False)
solutions = db.relationship('Result', backref='rebus', lazy='dynamic')
points = db.Column(db.Integer, default=1)
class Result(db.Model):
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
riddle_id = db.Column(db.Integer, db.ForeignKey('riddle.id'))
Answer the question
In order to leave comments, you need to log in
The solution was found:
SELECT *
FROM riddle
EXCEPT
SELECT riddle.*
FROM riddle
JOIN result ON result.riddle_id = riddle.id
WHERE result.user_id = 1
riddle = Riddle.query.filter(Riddle.theme == theme_id) \
.except_(Riddle.query.join(Result, Result.riddle_id == Riddle.id) \
.filter(Result.user_id == user.id)).all()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question