From acb74a8577dc02a1e25ac9572d4d3a7157732480 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 29 May 2017 20:31:09 +1200 Subject: [PATCH] Fix $class variable from being clobbered The $class variable gets overwritten in the function. This causes error messages to be less helpful. For example if you setup a has_many but forget the has_one on the other side the error will look something like `[Emergency] Uncaught Exception: No has_one found on class 'SomeObject', the has_many relation from 'SilverStripe\View\ViewableData' to 'SomeObject' requires a has_one on 'SomeObject'` fixing this gives a more useful error, like `[Emergency] Uncaught Exception: No has_one found on class 'SomeObject', the has_many relation from 'Page' to 'SomeObject' requires a has_one on 'SomeObject'` --- src/ORM/DataObjectSchema.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ORM/DataObjectSchema.php b/src/ORM/DataObjectSchema.php index f1e8f32b6..49be58e5f 100644 --- a/src/ORM/DataObjectSchema.php +++ b/src/ORM/DataObjectSchema.php @@ -922,9 +922,9 @@ class DataObjectSchema if (empty($remoteField)) { // look for remote has_one joins on this class or any parent classes $remoteRelationsMap = array_flip($remoteRelations); - foreach (array_reverse(ClassInfo::ancestry($class)) as $class) { - if (array_key_exists($class, $remoteRelationsMap)) { - $remoteField = $remoteRelationsMap[$class]; + foreach (array_reverse(ClassInfo::ancestry($class)) as $ancestryClass) { + if (array_key_exists($ancestryClass, $remoteRelationsMap)) { + $remoteField = $remoteRelationsMap[$ancestryClass]; break; } }