fix: delete_bom use .all() instead of .first() to delete all child records
This commit is contained in:
@ -214,12 +214,16 @@ def delete_bom(bom_no):
|
|||||||
if version:
|
if version:
|
||||||
query = query.filter_by(version=version)
|
query = query.filter_by(version=version)
|
||||||
|
|
||||||
exist = query.first()
|
# 【核心修复】:使用 .all() 查出该 BOM 版本下的所有子件记录
|
||||||
if not exist:
|
records = query.all()
|
||||||
|
|
||||||
|
if not records:
|
||||||
return jsonify({'code': 404, 'msg': 'BOM 不存在'}), 404
|
return jsonify({'code': 404, 'msg': 'BOM 不存在'}), 404
|
||||||
|
|
||||||
# 删除(改为对象级删除以触发审计事件)
|
# 循环删除所有关联记录(逐个 delete 可触发 SQLAlchemy 监听器记录审计日志)
|
||||||
db.session.delete(exist)
|
for rec in records:
|
||||||
|
db.session.delete(rec)
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return jsonify({
|
return jsonify({
|
||||||
'code': 200,
|
'code': 200,
|
||||||
|
|||||||
Reference in New Issue
Block a user