Add the constraints for a relationship query.

@param \Mellivora\Database\Eloquent\Builder $query
@param \Mellivora\Database\Eloquent\Builder $parentQuery
@param array|mixed                          $columns

@return \Mellivora\Database\Eloquent\Builder
192299
public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*'])
    {
        if ($parentQuery->getQuery()->from === $query->getQuery()->from) {
            return $this->getRelationExistenceQueryForSelfJoin($query, $parentQuery, $columns);
        }

        $this->performJoin($query);

        return parent::getRelationExistenceQuery($query, $parentQuery, $columns);
    }
917115
public function apply(ColumnInterface $column, Builder $query, $queryString, $queryParams)
    {
        $queryString = $this->parseValue($queryString);

        if (($metaInstance = $column->getMetaData()) instanceof ColumnMetaInterface) {
            if (method_exists($metaInstance, 'onFilterSearch')) {
                $metaInstance->onFilterSearch($column, $query, $queryString, $queryParams);

                return;
            }
        }

        if (is_callable($callback = $column->getFilterCallback())) {
            $callback($column, $query, $queryString, $queryParams);

            return;
        }

        if (is_callable($callback = $this->getCallback())) {
            $callback($column, $query, $queryString, $queryParams);

            return;
        }

        if (empty($queryString) && strlen($queryString) == 0) {
            return;
        }

        if (is_null($name = $this->getColumnName())) {
            $name = $column->getName();
        }

        if (strpos($name, '.') !== false) {
            $parts = explode('.', $name);
            $fieldName = array_pop($parts);
            $relationName = implode('.', $parts);

            $query->whereHas($relationName, function ($q) use ($queryString, $fieldName) {
                $this->buildQuery($q, $fieldName, $queryString);
            });
        } else {
            $this->buildQuery($query, $name, $queryString);
        }
    }
97169
public function getRelationExistenceQueryForSelfRelation(Builder $query, Builder $parentQuery, $columns = ['*'])
    {
        $query->from($query->getModel()->getTable().' as '.$hash = $this->getRelationCountHash());

        $query->join($this->throughParent->getTable(), $this->getQualifiedParentKeyName(), '=', $hash.'.'.$this->secondKey);

        if ($this->throughParentSoftDeletes()) {
            $query->whereNull($this->throughParent->getQualifiedDeletedAtColumn());
        }

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

        return $query->select($columns)->whereColumn(
            $parentQuery->getQuery()->from.'.'.$this->localKey, '=', $this->getQualifiedFirstKeyName()
        );
    }
439265
public function compileEdge(Builder $query, $parent, $related, $relationship = 'E', $values = [])
    {
        // Essentially we will force every insert to be treated as a batch insert which
        // simply makes creating the SQL easier for us since we can utilize the same
        // basic routine regardless of an amount of records given to us to insert.

        $from = $this->columnize([$parent->getAttributes()[$parent->getKeyName()]]);
        $to = $this->columnize([$related->getAttributes()[$related->getKeyName()]]);

//     code to check if relationship object exist or not
//        
//              if($relationship instanceof Relatio){
//            
//        }
        // Add content if there are the $values present
        $property_query = NULL;
        if ($values != NULL) {
            $property_query = "CONTENT " . json_encode($values);
        }
        return "create edge {$relationship->getType()} from $from to $to " . $property_query;

    }
377465
public function getParentRelationship(DataQuery $query)
    {
        // Create has_many
        if ($this->getForeignClass() === DataObject::class) {
            /** @internal Polymorphic many_many is experimental */
            $list = PolymorphicHasManyList::create(
                $this->getJoinClass(),
                $this->getForeignKey(),
                $this->getParentClass()
            );
        } else {
            $list = HasManyList::create($this->getJoinClass(), $this->getForeignKey());
        }
        $list = $list->setDataQueryParam($this->extractInheritableQueryParameters($query));

        // Limit to given foreign key
        $foreignID = $query->getQueryParam('Foreign.ID');
        if ($foreignID) {
            $list = $list->forForeignID($foreignID);
        }
        return $list;
    }
475013
public function getRelationCountQuery(Query $query, Query $parent)
    {
        $parentTable = $this->parentMap->getTable();

        $this->setJoin($query);

        $query->select(new Expression('count(*)'));

        $key = $this->wrap($parentTable.'.'.$this->firstKey);

        return $query->where($this->getHasCompareKey(), '=', new Expression($key));
    }
1222979
public function alterQueryBuilderExceptWithParentRoot($query, $parent_id)
    {
        if (is_null($parent_id)) {
            return $query;
        }
        $parent = $this->find($parent_id);
        $query->andWhere(
            $query->getRootAliases()[0] . '.lft > ' . $this->addNamedParameter('rgt', $parent->getRgt(), $query)
            . ' OR ' . $query->getRootAliases()[0] . '.lft < ' . $this->addNamedParameter('lft', $parent->getLft(), $query)
        );
        return $query;
    }
780651
public function getRelationExistenceQueryForSelfRelation(Builder $query, Builder $parentQuery, $columns = ['*'])
    {
        $query->from($query->getModel()->getTable().' as '.$hash = $this->getRelationCountHash());

        $query->join($this->throughChild->getTable(), $this->getQualifiedParentKeyName(), '=', $hash.'.'.$this->ownerKey);

        if ($this->throughChildSoftDeletes()) {
            $query->whereNull($this->throughChild->getQualifiedDeletedAtColumn());
        }

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

        return $query->whereColumn(
            $hash.'.'.$query->getModel()->qualifyColumn($this->secondKey), '=', $this->getQualifiedSecondOwnerKeyName()
        );
    }
758751
public function getRelationCountQueryForSelfJoin(Builder $query, Builder $parent)
	{
		$query->select(new \Fly\Database\Query\Expression('count(*)'));

		$query->from($this->table.' as '.$hash = $this->getRelationCountHash());

		$key = $this->wrap($this->getQualifiedParentKeyName());

		return $query->where($hash.'.'.$this->foreignKey, '=', new \Fly\Database\Query\Expression($key));
	}
360148
public function getRelationExistenceQueryForSelfRelation(Builder $query, Builder $parentQuery, $columns = ['*'])
    {
        $query->from($query->getModel()->getTable().' as '.$hash = $this->getRelationCountHash());

        $this->performJoin($query);

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

        return $query->select($columns)->whereColumn(
            $parentQuery->getQuery()->from.'.'.$query->getModel()->getKeyName(), '=', $this->getQualifiedFirstKeyName()
        );
    }
816893
public function withParentIdAs(string $columnName)
    {
        call_user_func($this->callback, function ($idString, Table $parentTable) use ($columnName) {
            /** @var IEntityMapper $mapper */
            $mapper = call_user_func($this->mapperLoader);

            $mapper->addForeignKey(ForeignKey::createWithNamingConvention(
                $mapper->getPrimaryTableName(),
                [$columnName],
                $parentTable->getName(),
                [$parentTable->getPrimaryKeyColumnName()],
                $this->identifying
                    ? ForeignKeyMode::CASCADE
                    : ForeignKeyMode::SET_NULL,
                ForeignKeyMode::CASCADE
            ));

            return new ToOneRelation(
                $idString,
                $this->loadIds
                    ? new ToOneRelationIdentityReference($mapper, $this->bidirectionalRelationProperty)
                    : new ToOneRelationObjectReference($mapper, $this->bidirectionalRelationProperty),
                $columnName,
                $this->identifying
                    ? new IdentifyingRelationMode()
                    : new NonIdentifyingRelationMode()
            );
        });
    }
963318
public function getRelationQueryForSelfJoin(Builder $query, Builder $parent, $columns = ['*'])
	{
		$query->select($columns);

		$query->from($this->related->getTable().' as '.$hash = $this->getRelationCountHash());

		$this->related->setTable($hash);

		$this->setJoin($query);

		return parent::getRelationQuery($query, $parent, $columns);
	}
886803
public function query(
        Query $query,
        array $parameters = []
    ): Result {
        $this->load();

        return parent::query($query);
    }
19893
public function buildSqlQuery(IndexQueryInterface $query, array $columns = null)
    {
        $queryString = sprintf("SELECT `%s` FROM `%s`", implode("`,`", $columns), $query->getName());

        if ("" !== $criteria = $this->buildSqlConditions($query)) {
            $queryString .= sprintf(" WHERE %s", $criteria);
        }

        if (null !== $limit = $query->getLimit()) {
            $queryString .= sprintf(" LIMIT %d", $limit);
        }

        return $queryString;
    }
1159405
protected function prepareQueryBuilder($columns = ['*'])
    {
        $builder = $this->query->applyScopes();

        return $builder->addSelect(
            $this->shouldSelect($builder->getQuery()->columns ? [] : $columns)
        );
    }
1341173
public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*'])
    {
        if ($parentQuery->getQuery()->from === $query->getQuery()->from) {
            return $this->getRelationExistenceQueryForSelfRelation($query, $parentQuery, $columns);
        }

        if ($parentQuery->getQuery()->from === $this->throughParent->getTable()) {
            return $this->getRelationExistenceQueryForThroughSelfRelation($query, $parentQuery, $columns);
        }

        $this->performJoin($query);

        return $query->select($columns)->whereColumn(
            $this->getQualifiedLocalKeyName(), '=', $this->getQualifiedFirstKeyName()
        );
    }
844750
public function scopeFilterColumns($query, $columns = array(), $validate = false)
	{
		if ( sizeof($columns) > 0 ) {
			// Set columns that can be filtered
			$this->setColumns($columns);
		}
		// Validate columns
		if ( $validate ) {
			$this->validateColumns();	
		}
		// Ensure that query string is parsed at least once
		if ( sizeof($this->filterable['filters']) == 0 ) {
			$this->setQuerystring();
		}
		// Apply conditions to Eloquent query object
		if ( sizeof($this->filterable['filters']) > 0 ) {
			foreach ( $this->filterable['filters'] as $k => $v ) {
				$where = $v['boolean'];	
				if ( is_array($v['val']) ) {
					if ( isset($v['val']['start']) && isset($v['val']['end']) ) {
						// BETWEEN a AND b
						$query->whereBetween($k, array($v['val']['start'], $v['val']['end']));
					} else {
						// a = b OR c = d OR...
						$query->{$where}(function($q) use ($k, $v, $query)
						{
							foreach ( $v['val'] as $key => $val ) {
								$q->orWhere($k, $v['operator'], $val);	
							}	
						});
					}
				} else {
					// a = b
					$query->{$where}($k, $v['operator'], $v['val']);
				}
			}
		}
		// Apply callbacks
		if ( sizeof($this->filterable['callbacks']) > 0 ) {
			foreach ( $this->filterable['callbacks'] as $v ) {
				$v($query);	
			}
		}
		// Sorting
		if ( isset($this->filterable['qstring'][$this->filterable['orderby']]) && isset($this->filterable['columns'][$this->filterable['qstring'][$this->filterable['orderby']]]) ) {
			$order = isset($this->filterable['qstring'][$this->filterable['order']]) ? $this->filterable['qstring'][$this->filterable['order']] : 'asc';
			$query->orderBy($this->filterable['columns'][$this->filterable['qstring'][$this->filterable['orderby']]], $order);
		}
		return $query;
	}