v2.6更新
This commit is contained in:
@@ -71,18 +71,18 @@ class SubjectModel:
|
||||
|
||||
@staticmethod
|
||||
async def has_related_data(subject_id: int) -> bool:
|
||||
"""检查科目是否有关联数据"""
|
||||
return False
|
||||
"""检查科目是否有关联的作业数据"""
|
||||
sql = "SELECT COUNT(*) AS cnt FROM assignments WHERE subject_id = %s"
|
||||
result = await execute_one(sql, (subject_id,))
|
||||
return result and result.get("cnt", 0) > 0
|
||||
|
||||
@staticmethod
|
||||
async def delete(subject_id: int) -> bool:
|
||||
"""软删除科目(设置 is_active = 0),如果已禁用也返回成功"""
|
||||
"""真正删除科目记录"""
|
||||
subject = await SubjectModel.get_by_id(subject_id)
|
||||
if not subject:
|
||||
return False
|
||||
if subject.get("is_active") == 0:
|
||||
return True # 已禁用,视为成功
|
||||
sql = "UPDATE subjects SET is_active = 0 WHERE subject_id = %s"
|
||||
sql = "DELETE FROM subjects WHERE subject_id = %s"
|
||||
result = await execute_update(sql, (subject_id,))
|
||||
return result > 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user