Skip to content

Commit

Permalink
Fixed select inheritance on custom query objects
Browse files Browse the repository at this point in the history
  • Loading branch information
mario-deluna committed Nov 5, 2018
1 parent 0acca94 commit cbf7c43
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/Query/Sql/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

use ClanCats\Hydrahon\Query\Expression;

use ClanCats\Hydrahon\BaseQuery;

class Select extends SelectBase implements FetchableInterface
{
/**
Expand Down Expand Up @@ -62,6 +64,37 @@ class Select extends SelectBase implements FetchableInterface
*/
protected $forwardKey = false;

/**
* Inherit property values from parent query
*
* @param BaseQuery $parent
* @return void
*/
protected function inheritFromParent(BaseQuery $parent)
{
parent::inheritFromParent($parent);

if ($parent instanceof Select) {
$parent->copyTo($this);
}
}

/**
* Copy current queries select attributes to the given one
*
* @param Select $query
*/
public function copyTo(Select $query)
{
$query->fields = $this->fields;
$query->distinct = $this->distinct;
$query->orders = $this->orders;
$query->groups = $this->groups;
$query->joins = $this->joins;
$query->groupResults = $this->groupResults;
$query->forwardKey = $this->forwardKey;
}

/**
* Distinct select setter
*
Expand Down

0 comments on commit cbf7c43

Please sign in to comment.