From 23859ce22bda68ac5f5097515edb7c693816365a Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Tue, 1 Apr 2014 14:12:59 -0500
Subject: [PATCH] Throw error if relationship reverse is misconfigured

---
 include/class.orm.php | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/include/class.orm.php b/include/class.orm.php
index ef04e3d3e..b5541941d 100644
--- a/include/class.orm.php
+++ b/include/class.orm.php
@@ -17,6 +17,7 @@
 **********************************************************************/
 
 class OrmException extends Exception {}
+class OrmConfigurationException extends Exception {}
 
 class VerySimpleModel {
     static $meta = array(
@@ -111,7 +112,7 @@ class VerySimpleModel {
 
     static function _inspect() {
         if (!static::$meta['table'])
-            throw new OrmConfigurationError(
+            throw new OrmConfigurationException(
                 'Model does not define meta.table', get_called_class());
 
         // Break down foreign-key metadata
@@ -120,6 +121,9 @@ class VerySimpleModel {
                 list($model, $key) = explode('.', $j['reverse']);
                 $info = $model::$meta['joins'][$key];
                 $constraint = array();
+                if (!is_array($info['constraint']))
+                    throw new OrmConfigurationException(
+                        $j['reverse'].': Reverse does not specify any constraints');
                 foreach ($info['constraint'] as $foreign => $local) {
                     list(,$field) = explode('.', $local);
                     $constraint[$field] = "$model.$foreign";
-- 
GitLab