Skip to content

Commit

Permalink
fix boolean binding for json updates
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed May 27, 2016
1 parent 45fc861 commit 38acdd8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2067,6 +2067,8 @@ public function update(array $values)

$sql = $this->grammar->compileUpdate($this, $values);

$bindings = $this->grammar->prepareBindingsForUpdate($bindings, $values);

return $this->connection->update($sql, $this->cleanBindings($bindings));
}

Expand Down
12 changes: 12 additions & 0 deletions src/Illuminate/Database/Query/Grammars/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,18 @@ public function compileUpdate(Builder $query, $values)
return trim("update {$table}{$joins} set $columns $where");
}

/**
* Prepare the bindings for an update statement.
*
* @param array $bindings
* @param array $values
* @return array
*/
public function prepareBindingsForUpdate(array $bindings, array $values)
{
return $bindings;
}

/**
* Compile a delete statement into SQL.
*
Expand Down
22 changes: 22 additions & 0 deletions src/Illuminate/Database/Query/Grammars/MySqlGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,28 @@ protected function compileJsonUpdateColumn($key, JsonExpression $value)
return "{$field} = json_set({$field}, {$accessor}, {$value->getValue()})";
}

/**
* Prepare the bindings for an update statement.
*
* @param array $bindings
* @param array $values
* @return array
*/
public function prepareBindingsForUpdate(array $bindings, array $values)
{
$index = 0;

foreach ($values as $column => $value) {
if ($this->isJsonSelector($column) && is_bool($value)) {
unset($bindings[$index]);
}

$index++;
}

return $bindings;
}

/**
* Compile a delete statement into SQL.
*
Expand Down

0 comments on commit 38acdd8

Please sign in to comment.