How can flask do multi-table queries without foreign keys?

< H1 > user table < / H1 >

class User (db.Model):

id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(40), unique=True)  
password = db.Column(db.String(128)) 
< H1 > order form < / H1 >

class User (db.Model):

id = db.Column(db.Integer, primary_key=True)
buy_id = db.Column(db.Integer) -sharp ID  
sell_id = db.Column(db.Integer) -sharp ID
status = db.Column(db.Integer) -sharp
< H1 > SKU < / H1 >

class Sku (db.Model):

id = db.Column(db.Integer, primary_key=True)
sku_name = db.Column(db.String(40))  
money = db.Column(db.Float(20))

description: a user can be a seller or a buyer.

here are three tables. There is no foreign key association. You need to query according to the order status (for example: 0: closed, 1: waiting for payment, 3: waiting for delivery.). At the same time, the seller and product name corresponding to the order need to be displayed in the template.

I thought for a moment that it might be more complicated to set a foreign key. I don"t know which way is easier.


if I remember correctly, sqlalchemy requires that there must be a foreign key. So flask-sqlalchemy is no exception.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1c25dc2-32ff3.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1c25dc2-32ff3.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?