From b758eb9c455bd9c98150bb6762cd37896aa5d89a Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Tue, 1 Apr 2014 15:14:01 -0500
Subject: [PATCH] orm: Fix setup of InstrumentedList magic properties

Conflicts:
	include/class.orm.php
---
 include/class.orm.php | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/include/class.orm.php b/include/class.orm.php
index b9bda6a11..63ce1e085 100644
--- a/include/class.orm.php
+++ b/include/class.orm.php
@@ -52,6 +52,11 @@ class VerySimpleModel {
         // Update of foreign-key by assignment to model instance
         if (isset(static::$meta['joins'][$field])) {
             $j = static::$meta['joins'][$field];
+            if ($j['list'] && ($value instanceof InstrumentedList)) {
+                // Magic list property
+                $this->ht[$field] = $value;
+                return;
+            }
             // XXX: Ensure $value instanceof $j['fkey'][0]
             if ($value->__new__)
                 $value->save();
@@ -86,11 +91,12 @@ class VerySimpleModel {
         // Construct related lists
         if (isset(static::$meta['joins'])) {
             foreach (static::$meta['joins'] as $name => $j) {
-                if (isset($j['list']) && $j['list']) {
+                if (isset($this->ht[$j['local']])
+                        && isset($j['list']) && $j['list']) {
                     $fkey = $j['fkey'];
-                    $this->{$name} = new InstrumentedList(
+                    $this->set($name, new InstrumentedList(
                         // Send Model, Foriegn-Field, Local-Id
-                        array($fkey[0], $fkey[1], $this->{$j['local']})
+                        array($fkey[0], $fkey[1], $this->get($j['local'])))
                     );
                 }
             }
-- 
GitLab