From 17118f36b8870892e75f64b364759d6e96373a0d Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Mon, 28 Sep 2015 22:38:06 -0500 Subject: [PATCH] orm: Avoid crashing when building a model with select_related ... and some of the related models are null. --- include/class.orm.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/class.orm.php b/include/class.orm.php index a92d47668..0cfaf6422 100644 --- a/include/class.orm.php +++ b/include/class.orm.php @@ -1534,9 +1534,11 @@ class ModelInstanceManager extends ResultSet { $tail = array_pop($path); $m = $model; foreach ($path as $field) { - $m = $m->get($field); + if (!($m = $m->get($field))) + break; } - $m->set($tail, $this->getOrBuild($model_class, $record)); + if ($m) + $m->set($tail, $this->getOrBuild($model_class, $record)); } $offset += count($fields); } -- GitLab