如何在SQLAlchemy中使用where in filter?

2024-06-28 19:50:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我有两个表BdiDataLifeCycleBdiSourcePlatform。两个表都有一列event_id。我正在尝试连接event_id上的这两个表。但下面给出了错误。当我尝试调用API时。你知道吗

{
"message": {
"message": "Neither 'InstrumentedAttribute' object nor 'Comparator' object associated with BdiSourcePlatform.event_id has an attribute 'split'"
}
}

event_idBdiDataLifeCycle的主键,但在BdiSourcePlatformevent_id用作csv。 ^BdiSourcePlatform中的{}样本值。你知道吗

1个

1,2个

4、5、6

原料药:

@app.route("/api/bdi_pf_data", methods=["GET"])
def get_pf_data():
  if request.method == "GET":
    try:
        resp = db.session.query(BdiSourcePlatform,BdiDataLifeCycle)\
                .filter(BdiDataLifeCycle.event_id.in_(BdiSourcePlatform.event_id.split(',')))\
                .filter(BdiSourcePlatform.reference_bpt_template_id == BdiPlatformTemplate.template_id)\
                .values(BdiSourcePlatform.platform_id, BdiSourcePlatform.platform_name, BdiSourcePlatform.platform_type,\
                BdiSourcePlatform.reference_bpt_template_id, BdiDataLifeCycle.event_name,\
                BdiSourcePlatform.db_conn_verified_flg, BdiSourcePlatform.total_tables, BdiSourcePlatform.total_columns,\
                BdiSourcePlatform.data_ingestion_type, BdiSourcePlatform.provider_id, BdiSourcePlatform.transfer_type,\
                BdiSourcePlatform.platform_params, BdiSourcePlatform.event_id, BdiSourcePlatform.parent_platfoms,\
                BdiSourcePlatform.sor_aggregator_flg, BdiSourcePlatform.sor_producer_flg, BdiPlatformTemplate.template_name)
        d = []
        for i in resp:
            x = i.template_name.split('_')[0];
            j = {"platform_id": i.platform_id,"platform_name":i.platform_name,"platform_type":i.platform_type,"reference_bpt_template_id":i.reference_bpt_template_id,\
                "event_name":i.event_name,"db_conn_verified_flg":i.db_conn_verified_flg,"total_tables":i.total_tables,"total_columns":i.total_columns,\
                "data_ingestion_type": i.data_ingestion_type,"provider_id": i.provider_id,"transfer_type": i.transfer_type,"platform_params": i.platform_params,\
                "event_id": i.event_id,"parent_platfoms": i.parent_platfoms,"sor_aggregator_flg": i.sor_aggregator_flg,"sor_producer_flg": i.sor_producer_flg, "template_name":x\
                }
            d.append(j)
        return jsonify({"status":"success","response":d})
    except Exception, e:
        print "exception occured-->"
        print e
        return raiseError(BAD_REQUEST, {"message":str(e)})
  else:
    return jsonify({"status":"success"})

Tags: nameeventiddbdatatypetemplatetotal