From 19491f54eb4d7cd398f4eb984879cb647cec7f2f 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

---
 include/class.orm.php | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/include/class.orm.php b/include/class.orm.php
index 0450ef42f..8a06eb6ee 100644
--- a/include/class.orm.php
+++ b/include/class.orm.php
@@ -65,6 +65,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();
@@ -99,12 +104,12 @@ class VerySimpleModel {
         // Construct related lists
         if (isset(static::$meta['joins'])) {
             foreach (static::$meta['joins'] as $name => $j) {
-                if (isset($this->{$j['local']})
+                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