Skip to content

Commit

Permalink
feat(api): Remove many-to-many restrictions (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
pycook authored Feb 26, 2024
1 parent 26c3404 commit 7474a92
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions cmdb-api/api/lib/cmdb/ci_type.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding:utf-8 -*-

import copy

import toposort
from flask import abort
from flask import current_app
Expand Down Expand Up @@ -656,15 +657,15 @@ def add(cls, parent, child, relation_type_id, constraint=ConstraintEnum.One2Many
current_app.logger.warning(str(e))
return abort(400, ErrFormat.circular_dependency_error)

if constraint == ConstraintEnum.Many2Many:
other_c = CITypeRelation.get_by(parent_id=p.id, constraint=ConstraintEnum.Many2Many,
to_dict=False, first=True)
other_p = CITypeRelation.get_by(child_id=c.id, constraint=ConstraintEnum.Many2Many,
to_dict=False, first=True)
if other_c and other_c.child_id != c.id:
return abort(400, ErrFormat.m2m_relation_constraint.format(p.name, other_c.child.name))
if other_p and other_p.parent_id != p.id:
return abort(400, ErrFormat.m2m_relation_constraint.format(other_p.parent.name, c.name))
# if constraint == ConstraintEnum.Many2Many:
# other_c = CITypeRelation.get_by(parent_id=p.id, constraint=ConstraintEnum.Many2Many,
# to_dict=False, first=True)
# other_p = CITypeRelation.get_by(child_id=c.id, constraint=ConstraintEnum.Many2Many,
# to_dict=False, first=True)
# if other_c and other_c.child_id != c.id:
# return abort(400, ErrFormat.m2m_relation_constraint.format(p.name, other_c.child.name))
# if other_p and other_p.parent_id != p.id:
# return abort(400, ErrFormat.m2m_relation_constraint.format(other_p.parent.name, c.name))

existed = cls._get(p.id, c.id)
if existed is not None:
Expand Down

0 comments on commit 7474a92

Please sign in to comment.