From b158a7a438b9e7c02072594ce029a220adebcaa8 Mon Sep 17 00:00:00 2001 From: Han Lin Yap Date: Tue, 17 Jan 2012 17:25:51 +0100 Subject: [PATCH] DB::raw higher precedence than alias --- laravel/database/grammar.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/laravel/database/grammar.php b/laravel/database/grammar.php index f98a1cf7..66351e55 100644 --- a/laravel/database/grammar.php +++ b/laravel/database/grammar.php @@ -17,6 +17,11 @@ abstract class Grammar { */ public function wrap($value) { + // Expressions should be injected into the query as raw strings, + // so we do not want to wrap them in any way. We'll just return + // the string value from the expression to be included. + if ($value instanceof Expression) return $value->get(); + // If the value being wrapped contains a column alias, we need to // wrap it a little differently as each segment must be wrapped // and not the entire string. We'll split the value on the "as" @@ -28,11 +33,6 @@ public function wrap($value) return $this->wrap($segments[0]).' AS '.$this->wrap($segments[2]); } - // Expressions should be injected into the query as raw strings, - // so we do not want to wrap them in any way. We'll just return - // the string value from the expression to be included. - if ($value instanceof Expression) return $value->get(); - // Since columns may be prefixed with their corresponding table // name so as to not make them ambiguous, we will need to wrap // the table and the column in keyword identifiers.