Skip to content

Commit

Permalink
allow to use null or empty arrays in select->by()
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Dec 21, 2015
1 parent ffc1796 commit 7af8984
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/Queries/WhereTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,32 @@ public function orWhere($where, $marks = null)
/**
* Adds a WHERE field = :value clause.
*
* @param string $field
* @param int|array $value
* @param string $field
* @param null|int|array $value
*
* @return self
*/
public function by($field, $value)
{
if (is_array($value)) {
if (empty($value)) {
return $this->where("`{$this->entity->name}`.`{$field}` IS NULL");
}

return $this->where("`{$this->entity->name}`.`{$field}` IN (:{$field})", [":{$field}" => $value]);
}

if ($value === null) {
return $this->where("`{$this->entity->name}`.`{$field}` IS NULL");
}

return $this->where("`{$this->entity->name}`.`{$field}` = :{$field}", [":{$field}" => $value]);
}

/**
* Adds a WHERE id = :id clause.
*
* @param int|array $id
* @param null|int|array $id
*
* @return self
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Row.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function __set($name, $value)
}

/**
* Magic method to check if a property is defined or not
* Magic method to check if a property is defined or not.
*
* @param string $name Property name
*
Expand Down

0 comments on commit 7af8984

Please sign in to comment.