Skip to content

Commit 754ee6a

Browse files
authored
Merge pull request #2 from zunnu/3.x-dev
Error handling for association registration
2 parents b0c478b + bb7c9c5 commit 754ee6a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/Gate.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,16 @@ private function _associations($model, $plugin = null) {
163163
if($associations = $setModel->associations()) {
164164
foreach ($associations->normalizeKeys($associations->getIterator()) as $key => $association) {
165165
$source = $association->source();
166-
$target = $association->target();
166+
167+
try {
168+
$target = $association->target();
169+
} catch (\Exception $e) {
170+
$association->target()->setRegistryAlias(ucfirst($association->getProperty()) . $association->getName());
171+
$association->target()->setAlias(ucfirst($association->getProperty()) . $association->getName());
172+
$association->setName(ucfirst($association->getProperty()) . $association->getName());
173+
$target = $association->target();
174+
}
175+
167176
$sourceRegistery = 'App';
168177
$targetRegistery = 'App';
169178

0 commit comments

Comments
 (0)