From 5560ab29430680f74328c8cf23e0825a3ebcfea5 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Sun, 15 Jul 2018 06:07:09 +0000 Subject: [PATCH] dblayeroo : allow to orderAdd on aliases too git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@4285 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- Tests/dblayerooComplet.php | 17 +++++++++++++++++ dblayeroo.php | 6 ++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Tests/dblayerooComplet.php b/Tests/dblayerooComplet.php index 716fd44..a1f3057 100644 --- a/Tests/dblayerooComplet.php +++ b/Tests/dblayerooComplet.php @@ -957,4 +957,21 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase $this->assertSame (array (0=>array ("ALIAS"=>"where2")), $res); } + + public function test_orderAdd_alias1 () + { + $tbl2 = $this->tbl2 (); + $res = $tbl2->select () + ->displayAdd ("uid", "max") + ->orderAdd ("max","ASC") + ->execute (); + $tbl2->disconnect (); + $this->assertSame (array ( + array ('max' => 1), + array ('max' => 4), + array ('max' => 5), + array ('max' => 6), + ), $res); + } + } diff --git a/dblayeroo.php b/dblayeroo.php index 98f31da..cf2698c 100644 --- a/dblayeroo.php +++ b/dblayeroo.php @@ -2063,9 +2063,11 @@ class dblayeroo if (! in_array ($sort, array ("ASC", "DESC", "NATASC", "NATDESC"))) $this->DBException ( "Invalid sort provided (not ASC nor DESC nor NATASC nor NATDESC)"); - if (! array_key_exists ($field, $this->fields)) + if (! array_key_exists ($field, $this->fields) && + ! in_array ($field, $this->displayAlias)) $this->DBException (sprintf ( - "Invalid field to orderAdd '%s' : not defined in table", $field)); + "Invalid field to orderAdd '%s' : not defined in table nor in alias", + $field)); $plus = ""; if (substr ($sort, 0, 3) === "NAT") {