From 8c1aa65e0ddc3dde2db60246c283932c894bcbdd Mon Sep 17 00:00:00 2001 From: hashstudio Date: Thu, 5 May 2016 10:47:44 +0300 Subject: [PATCH] Order by raw bindings --- src/Pixie/QueryBuilder/Adapters/BaseAdapter.php | 7 ++++++- src/Pixie/QueryBuilder/QueryBuilderHandler.php | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Pixie/QueryBuilder/Adapters/BaseAdapter.php b/src/Pixie/QueryBuilder/Adapters/BaseAdapter.php index ade1a1b..4309afe 100644 --- a/src/Pixie/QueryBuilder/Adapters/BaseAdapter.php +++ b/src/Pixie/QueryBuilder/Adapters/BaseAdapter.php @@ -54,9 +54,13 @@ public function select($statements) // Order bys $orderBys = ''; + $orderBindings = []; if (isset($statements['orderBys']) && is_array($statements['orderBys'])) { foreach ($statements['orderBys'] as $orderBy) { $orderBys .= $this->wrapSanitizer($orderBy['field']) . ' ' . $orderBy['type'] . ', '; + if ($orderBy['bindings']) { + $orderBindings = array_merge($orderBindings, $orderBy['bindings']); + } } if ($orderBys = trim($orderBys, ', ')) { @@ -92,7 +96,8 @@ public function select($statements) $bindings = array_merge( $whereBindings, - $havingBindings + $havingBindings, + $orderBindings ); return compact('sql', 'bindings'); diff --git a/src/Pixie/QueryBuilder/QueryBuilderHandler.php b/src/Pixie/QueryBuilder/QueryBuilderHandler.php index 134fba0..c31d7ad 100644 --- a/src/Pixie/QueryBuilder/QueryBuilderHandler.php +++ b/src/Pixie/QueryBuilder/QueryBuilderHandler.php @@ -530,14 +530,17 @@ public function orderBy($fields, $defaultDirection = 'ASC') foreach ($fields as $key => $value) { $field = $key; $type = $value; + $bindings = []; if (is_int($key)) { $field = $value; $type = $defaultDirection; } if (!$field instanceof Raw) { $field = $this->addTablePrefix($field); + } else { + $bindings = $field->getBindings(); } - $this->statements['orderBys'][] = compact('field', 'type'); + $this->statements['orderBys'][] = compact('field', 'type', 'bindings'); } return $this;