Merge pull request #244 from codler/patch-7

DB::raw should have higher precedence than alias
This commit is contained in:
Taylor Otwell 2012-01-21 08:45:09 -08:00
commit 4737c6d8a9
1 changed files with 5 additions and 5 deletions

View File

@ -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.