diff --git a/include/class.orm.php b/include/class.orm.php index cac0eb39eab5a1c8e566314520d0ec5c0f2fa96a..a92d476682f0ed2373adffe3c18dd1f35222ef88 100644 --- a/include/class.orm.php +++ b/include/class.orm.php @@ -919,6 +919,7 @@ class QuerySet implements IteratorAggregate, ArrayAccess, Serializable, Countabl var $distinct = array(); var $lock = false; var $chain = array(); + var $options = array(); const LOCK_EXCLUSIVE = 1; const LOCK_SHARED = 2; @@ -986,6 +987,9 @@ class QuerySet implements IteratorAggregate, ArrayAccess, Serializable, Countabl return $this; } function order_by($order, $direction=false) { + if ($order === false) + return $this->options(array('nosort' => true)); + $args = func_get_args(); if (in_array($direction, array(self::ASC, self::DESC))) { $args = array($args[0]); @@ -1184,6 +1188,11 @@ class QuerySet implements IteratorAggregate, ArrayAccess, Serializable, Countabl return $this; } + function options($options) { + $this->options = array_merge($this->options, $options); + return $this; + } + function countSelectFields() { $count = count($this->values) + count($this->annotations); if (isset($this->extra['select'])) @@ -1259,6 +1268,7 @@ class QuerySet implements IteratorAggregate, ArrayAccess, Serializable, Countabl // Load defaults from model $model = $this->model; $query = clone $this; + $options += $this->options; if ($options['nosort']) $query->ordering = array(); elseif (!$query->ordering && $model::getMeta('ordering')) diff --git a/include/class.thread.php b/include/class.thread.php index 8ac7534bf7baa5261df548059ee693d01220dec0..ffffe918d51e9229a7925578729a4756a2b92dbe 100644 --- a/include/class.thread.php +++ b/include/class.thread.php @@ -1128,6 +1128,7 @@ implements TemplateVariable { // in-reply-to header if ($entry = ThreadEntry::objects() ->filter(array('email_info__mid' => $mailinfo['mid'])) + ->order_by(false) ->first() ) { $seen = true; @@ -1201,7 +1202,8 @@ implements TemplateVariable { $mid = "$left@$right"; } $entries = ThreadEntry::objects() - ->filter(array('email_info__mid' => $mid)); + ->filter(array('email_info__mid' => $mid)) + ->order_by(false); foreach ($entries as $t) { // Capture the first match thread item if (!$thread)