To join multiple tables with multiple foreign keys in Flask using SQLAlchemy, you can use the join() method along with the join() method of the previous join result. Here's an example:

from flask import Flask
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'your_database_uri'
db = SQLAlchemy(app)

# Define your models
class HandleGaochabiaoComparisonResult(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    zhenduan_id = db.Column(db.Integer, db.ForeignKey('handle_gaochabiao_zhenduan.id'))
    # ...

class HandleGaochabiaoCezhan(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    # ...

class HandleGaochabiaoMatchs(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    ceduans_details_id = db.Column(db.Integer, db.ForeignKey('handle_gaochabiao_ceduans_details.id'))
    # ...

class HandleGaochabiaoCeduansDetails(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    # ...

class HandleGaochabiaoZhenduan(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    # ...

# Perform the join query
result = HandleGaochabiaoComparisonResult.query \
    .join(HandleGaochabiaoZhenduan) \
    .join(HandleGaochabiaoMatchs) \
    .join(HandleGaochabiaoCeduansDetails) \
    .join(HandleGaochabiaoCezhan) \
    .all()

In this example, we define the models for each table and their relationships using foreign keys. Then, we perform the join query by chaining the join() method for each join operation. Finally, we retrieve the results using the all() method.

Note: Replace 'your_database_uri' with the actual URI of your database

python flask 多重外键HandleGaochabiaoComparisonResultqueryjoinHandleGaochabiaoCezhan HandleGaochabiaoMatchsceduans_details HandleGaochabiaoComparisonResultzhenduan

原文地址: https://www.cveoy.top/t/topic/ixuG 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录