Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use having instead of where #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/QueryBuilderParser/QueryBuilderParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class QueryBuilderParser

protected $fields;

protected $useHaving = false;

/**
* @param array $fields a list of all the fields that are allowed to be filtered by the QueryBuilder
*/
Expand All @@ -21,6 +23,18 @@ public function __construct(array $fields = null)
$this->fields = $fields;
}

/**
* Use "having" instead of "where" in the queries.
*
* @return QueryBuilderParser
*/
public function setUseHaving()
{
$this->useHaving = true;

return $this;
}

/**
* QueryBuilderParser's parse function!
*
Expand Down Expand Up @@ -253,6 +267,10 @@ protected function convertIncomingQBtoQuery(Builder $query, stdClass $rule, $val
return $this->makeQueryWhenNull($query, $rule, $sqlOperator, $condition);
}

if ($this->useHaving) {
return $query->having($rule->field, $sqlOperator['operator'], $value, $condition);
}

return $query->where($rule->field, $sqlOperator['operator'], $value, $condition);
}

Expand Down