Skip to content

Commit

Permalink
Fix NavigationClassMustBeAConstraintClassOfRel (iTwin#2015)
Browse files Browse the repository at this point in the history
* Fix NavigationClassMustBeAConstraintClassOfRel

* change log

* PR Updates
  • Loading branch information
christophermlawson authored Aug 16, 2021
1 parent d1cdaa2 commit ebcf17c
Show file tree
Hide file tree
Showing 3 changed files with 319 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@bentley/ecschema-editing",
"comment": "",
"type": "none"
}
],
"packageName": "@bentley/ecschema-editing",
"email": "[email protected]"
}
24 changes: 20 additions & 4 deletions core/ecschema-editing/src/Validation/ECRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,15 +453,31 @@ export async function* validateNavigationProperty(property: AnyProperty): AsyncI
yield new Diagnostics.NavigationRelationshipAbstractConstraintEntityOrMixin(property, [property.fullName, relationship.fullName]);
}

let concreteClass = false;
const isClassSupported = async (ecClass: ECClass, propertyName: string, constraintName: string): Promise<boolean> => {
if (constraintName === ecClass.fullName && undefined !== await ecClass.getProperty(propertyName))
return true;

const inheritedProp = await ecClass.getInheritedProperty(propertyName);
if (inheritedProp && constraintName === inheritedProp.class.fullName)
return true;

const baseClass = await ecClass.baseClass;
if (!baseClass)
return false;

return isClassSupported(baseClass, propertyName, constraintName);
};

let classSupported = false;
if (thisConstraint.constraintClasses) {
for (const constraintClass of thisConstraint.constraintClasses) {
if (constraintClass.fullName === property.class.fullName)
concreteClass = true;
classSupported = await isClassSupported(property.class, property.name, constraintClass.fullName);
if (classSupported)
break;
}
}

if (!concreteClass)
if (!classSupported)
yield new Diagnostics.NavigationClassMustBeAConstraintClassOfRelationship(property, [property.class.name, property.name, relationship.fullName, navigationClassSide]);

if (thatConstraint.multiplicity === RelationshipMultiplicity.oneMany || thatConstraint.multiplicity === RelationshipMultiplicity.zeroMany) {
Expand Down
Loading

0 comments on commit ebcf17c

Please sign in to comment.