I have 2 table like this:
class Role(db.Model):
__tablename__ = 'roles'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(64), unique=True)
index = db.Column(db.String(64))
users = db.relationship('User',
backref='role', lazy='dynamic')
class User(UserMixin, db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(64), unique=True, index=True)
role_id = db.Column(db.Integer, db.ForeignKey('roles.id'))
Then I try to making 2 kinds of query to get data for the relationship models.
first, I make it like this:
user = db.session.query(User, Role.index).filter_by(email=form.email.data).first()
and the second one I use join statement on that:
user = db.session.query(User, Role.index).join(Role).filter(User.email==form.email.data).first()
My questions are, what's the difference in that query while in the second one I use the join statement but the result still same.
For the fast query or performance, should I use the first or the second one..?