@@ -490,27 +490,32 @@ class CodeChunks {
490490 ModelRelation ? srcRel;
491491 ModelProperty ? srcProp;
492492
493+ final throwAmbiguousError = (String prop, String rel) =>
494+ throw InvalidGenerationSourceError (
495+ 'Ambiguous relation backlink source for ${entity .name }.${bl .name }.'
496+ ' Matching property: $prop .'
497+ ' Matching standalone relation: $rel .' );
498+
493499 if (bl.srcField.isEmpty) {
494500 final matchingProps = srcEntity.properties
495501 .where ((p) => p.isRelation && p.relationTarget == entity.name);
496502 final matchingRels =
497503 srcEntity.relations.where ((r) => r.targetId == entity.id);
498504 final candidatesCount = matchingProps.length + matchingRels.length;
499505 if (candidatesCount > 1 ) {
500- throw InvalidGenerationSourceError (
501- 'Ambiguous relation backlink source for ${entity .name }.${bl .name }.'
502- ' Matching property: $matchingProps .'
503- ' Matching standalone relations: $matchingRels .' );
506+ throwAmbiguousError (matchingProps.toString (), matchingRels.toString ());
504507 } else if (matchingProps.isNotEmpty) {
505508 srcProp = matchingProps.first;
506509 } else if (matchingRels.isNotEmpty) {
507510 srcRel = matchingRels.first;
508511 }
509512 } else {
510- srcProp = srcEntity.findPropertyByName (bl.srcField);
511- if (srcProp == null ) {
512- srcRel =
513- srcEntity.relations.firstWhereOrNull ((r) => r.name == bl.srcField);
513+ srcProp = srcEntity.findPropertyByName (bl.srcField + 'Id' );
514+ srcRel =
515+ srcEntity.relations.firstWhereOrNull ((r) => r.name == bl.srcField);
516+
517+ if (srcProp != null && srcRel != null ) {
518+ throwAmbiguousError (srcProp.toString (), srcRel.toString ());
514519 }
515520 }
516521
0 commit comments