From 93a34c43b134f4c1f815eb4e36ce3d6584196629 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Wed, 13 Apr 2016 15:27:05 -0400 Subject: [PATCH] orm: Don't null out value on assignment This fixes an issue where the PK of ThreadEntry will be NULLed in the following code ```php $entry = ThreadEntry::create(array(...)); $entry->save(); $entry->email_info = new ThreadEntryEmailInfo(array( 'mid' => 'xyzAbc', )); ``` In the above code, the $entry->__set('email_info', <ThreadEntryEmailInfo>) would be invoked. The ThreadEntryEmailInfo object is new, and so will cause the local part of the relationship (`id` in this case) to become null further down in the `__set` method. This issue is fixed in this commit by removing the NULL assignment to the new object. This was added in 113227665e527483d6ad6063edba6f2128c365a4, however, it is unclear why the null assignment is performed. --- include/class.orm.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/include/class.orm.php b/include/class.orm.php index c71f0e1e6..9255b8fe9 100644 --- a/include/class.orm.php +++ b/include/class.orm.php @@ -429,11 +429,7 @@ class VerySimpleModel { } // Capture the object under the object's field name $this->ht[$field] = $value; - if ($value->__new__) - // save() will be performed when saving this object - $value = null; - else - $value = $value->get($j['fkey'][1]); + $value = $value->get($j['fkey'][1]); // Fall through to the standard logic below } // Capture the foreign key id value -- GitLab