Add whereHas subquery on the mapped attribute relation.

@param  \Sofa\Eloquence\Builder $query
@param  string $method
@param  \Sofa\Hookable\Contracts\ArgumentBag $args
@param  string $target
@param  string $column
@return \Sofa\Eloquence\Builder
347229
protected function mappedHasQuery(Builder $query, $method, ArgumentBag $args, $target, $column)
    {
        $boolean = $this->getMappedBoolean($args);

        $operator = $this->getMappedOperator($method, $args);

        $args->set('column', $column);

        return $query
            ->has($target, $operator, 1, $boolean, $this->getMappedWhereConstraint($method, $args))
            ->with($target);
    }
43267
@SafeVarargs
  public static Query query(DB db, String sql, Object... args) {
    return new Query(db, sql, args);
  }
97896
public function findWhere(array $where, $columns = ['*'])
    {
        $this->applyCriteria();
        $this->applyScope();

        $this->applyConditions($where);

        $model = $this->model->get($columns);
        $this->resetModel();

        return $this->parserResult($model);
    }
822019
private static function executeQuery($db, $method, array $args)
    {
        self::$query_count++;
        self::debugStart(current($args)); // sql is always the first arg
        $ret = call_user_func_array(array($db, $method), $args);
        self::debugEnd();

        if (MDB2::isError($ret)) {
            throw new SwatDBException($ret);
        }

        return $ret;
    }
53053
protected function whereBasic(Builder $query, $where)
    {
        if (Str::contains(strtolower($where['operator']), 'like')) {
            return sprintf(
                '%s::text %s %s',
                $this->wrap($where['column']),
                $where['operator'],
                $this->parameter($where['value'])
            );
        }

        return parent::whereBasic($query, $where);
    }
347161
public TResult query(String where, String[] whereArgs) {
		TResult result = userDb.query(getTableName(), table.getColumnNames(),
				where, whereArgs, null, null, null);
		prepareResult(result);
		return result;
	}
254456
public function order(string $column, string $method = "DESC") : QueryBuilder
    {
        $this->_query[] = "ORDER BY";
        $this->_query[] = "`". $this->sanitize($column) ."`";
        $this->_query[] = (strtoupper($method) === "DESC") ? "DESC" : "ASC";

        return $this;
    }
866473
private function addIntResultMethod(QueryBuilderResult $query, $methodName)
    {
        $intResultMethod = function () use ($query) {
            $sth = $this->pdo->prepare($query->getSql());
            $sth->execute(func_get_args());
            return $sth->rowCount();
        };

        $this->methods[$methodName] = \Closure::bind($intResultMethod, $this, get_class());
    }
7777
protected function _buildWhere($query, $where)
    {
        $clause = '';

        if (isset($where['condition'])) {
            $clause .= ' '.$where['condition'];
        }

        //converts subclause to string only if there's at least one where statement in it
        if (isset($where['clause'])) {
            if (empty($where['clause'])) {
                return '';
            }

            $clause .= ' (';
            foreach ($where['clause'] as $subwhere) {
                $clause .= $this->_buildWhere($query, $subwhere);
            }
            $clause .= ' )';

            return $clause;
        }

        list($columns, $property) = array_values(AnDomainQueryHelper::parseColumn($query, $where['property']));

        $value = isset($where['value']) ?  $where['value'] : null;
        $where['property'] = pick($columns, $where['property']);

        if ($property && !$value instanceof AnDomainQuery) {
            $constraint = $where['constraint'];

            if (is_object($value) || is_array($columns)) {
                if ($value instanceof AnObjectSet || is_array($value)) {
                    $values = $value;
                    $keys = array();
                    $clauses = array();
                    foreach ($values as $value) {
                        $columns = $property->serialize($value);
                        foreach ($columns as $column => $value) {
                            $keys[$column][] = $value;
                        }
                    }

                    foreach ($keys as $key => $values) {
                        $clauses[] = $this->_buildWhere($query, array('property' => $key, 'constraint' => $constraint, 'value' => $values));
                    }

                    $clause .= ' ('.implode(' AND ', $clauses).')';

                    return $clause;
                } else {
                    $columns = $property->serialize($value);

                    $clauses = array();
                    foreach ($columns as $column => $value) {
                        $clauses[] = $this->_buildWhere($query, array('property' => $column, 'constraint' => $constraint, 'value' => $value));
                    }

                    $clause .= ' ('.implode(' AND ', $clauses).')';

                    return $clause;
                }
            }
        }

        $clause  .= ' '.$where['property'];

        if (isset($where['constraint'])) {
            $value = $this->_store->quoteValue($where['value']);

            if ($value === 'NULL') {
                //force correct constraint
                if (strpos($where['constraint'], 'IS') === false) {
                    if (strpos($where['constraint'], '<>') !== false) {
                        $where['constraint'] = ' IS NOT ';
                    } elseif (strpos($where['constraint'], '=') !== false) {
                        $where['constraint'] = ' IS ';
                    }
                }
            }

            if (in_array($where['constraint'], array('IN', 'NOT IN'))) {
                $value = ' ( '.$value.' ) ';
            }

            $clause .= ' '.$where['constraint'].' '.$value;
        }

        return $clause;
    }
939686
protected function map_filter( $id, $method, $arg_count ) {
		if ( empty( $this->filter_map[ $id ] ) ) {
			$this->filter_map[ $id ] = function () use ( $method, $arg_count ) {
				return call_user_func_array( [ $this, $method ], array_slice( func_get_args(), 0, $arg_count ) );
			};
		}

		return $this->filter_map[ $id ];
	}
1023285
public function getRelationExistenceQueryForSelfRelation(Builder $query, Builder $parentQuery, $columns = ['*'])
    {
        $query->from($query->getModel()->getTable().' as '.$hash = $this->getRelationCountHash());

        $query->getModel()->setTable($hash);

        return $query->select($columns)->whereColumn(
            $this->getQualifiedParentKeyName(), '=', $hash.'.'.$this->getForeignKeyName()
        );
    }
458
private static function _setWhere($where, QueryBuilder $query, string $primaryKey = "id") : QueryBuilder
    {
        if(!is_array($where)) {
            return $query->where([
                $primaryKey => $where
            ]);
        }

        $columns = $where;

        unset($columns["ORDER BY"]);
        unset($columns["LIMIT"]);
        unset($columns["OFFSET"]);

        if(!empty($columns)) {
            $query->where($columns);
        }

        if(isset($where["ORDER BY"])) {
            $order = $where["ORDER BY"];
            if(!is_array($order)) {
                $order = [$order];
            }

            $query->order(... $order);
        }
        if(isset($where["LIMIT"])) {
            $limit = $where["LIMIT"];
            if(!is_array($limit)) {
                $limit = [$limit];
            }

            $query->limit(... $limit);
        }
        if(isset($where["OFFSET"])) {
            $query->offset($where["OFFSET"]);
        }

        return $query;
    }
531111
public function replace($column, $target, $replacement)
    {
        $this->queryBuilder->replace($column, $target, $replacement);
        return $this;
    }
872740
protected function addHasWhere( Builder $hasQuery, Relation $relation, $operator, $count, $boolean )
	{
		$hasQuery->mergeModelDefinedRelationConstraints( $relation->getQuery() );

		if ( $this->shouldRunExistsQuery( $operator, $count ) )
		{
			$not = ( $operator === '<' && $count === 1 );

			return $this->addWhereExistsQuery( $hasQuery->toBase(), $boolean, $not );
		}

		return $this->whereCountQuery( $hasQuery->toBase(), $operator, $count, $boolean );
	}
425794
protected function orderByMapped(Builder $query, ArgumentBag $args, $table, $column, $target)
    {
        $query->with($target)->getQuery()->orderBy("{$table}.{$column}", $args->get('direction'));

        return $query;
    }
990334
public AnimaQuery<T> in(String column, Object... args) {
        if (null == args || args.length == 0) {
            log.warn("Column: {}, query params is empty.");
            return this;
        }
        conditionSQL.append(" AND ").append(column).append(" IN (");
        this.setArguments(args);
        conditionSQL.append(")");
        return this;
    }
333691
protected static function applyFilter($query, $column, $searchValue)
    {
        if ($methodName = self::hasCustomSearch($column)) {
            return self::$class::$methodName($query, $searchValue);
        }

        if (isRelationColumn($column)) {
            return self::applyRelationFilter($query, $column, $searchValue);
        }

        $searchValue = '%'.$searchValue.'%';

        return $query->orWhere($column, 'like', "$searchValue");
    }