Skip to content

Commit 00fc48a

Browse files
authored
Add error message if relationship is missing for dot notation (#71)
1 parent 6074668 commit 00fc48a

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/RelationshipGraph/Graph.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,24 @@ private function buildEdges(): void
292292

293293
// A dot notation is available, so we can map this immediately and continue
294294
if ($caresRelation) {
295+
$relationType = $this->getRelationType($careClassName, $caresRelation);
296+
297+
if (!$relationType) {
298+
$errors[] = sprintf(
299+
'Dot notation %s provided for %s::%s, but no corresponding relationship found in %s.'
300+
. ' You might need to add a has_many, has_one, belongs_to, etc in %s',
301+
sprintf('%s.%s', $careClassName, $caresRelation),
302+
$className,
303+
$relation,
304+
$careClassName,
305+
$careClassName
306+
);
307+
308+
continue;
309+
}
310+
295311
$careNode = $this->findOrCreateNode($careClassName);
296-
$edges[] = new Edge(
297-
$careNode,
298-
$node,
299-
$caresRelation,
300-
$this->getRelationType($careClassName, $caresRelation)
301-
);
312+
$edges[] = new Edge($careNode, $node, $caresRelation, $relationType);
302313

303314
continue;
304315
}

0 commit comments

Comments
 (0)