Add the constraints for a relationship count query.

        :type query: Builder
        :type parent: Builder

        :rtype: Builder
324884
def get_relation_count_query(self, query, parent):
        
        query = super(MorphOneOrMany, self).get_relation_count_query(query, parent)

        return query.where(self._morph_type, self._morph_class)
1160674
def _add_relations(self, relations):
        """"""
        for k, v in six.iteritems(relations):
            self.d.relate(k, v)
354914
public function addEagerConstraints(array $models)
    {
        // Get the parent node's placeholder.
        $parentNode = $this->query->getQuery()->modelAsNode($this->parent->getTable());
        // Tell the query that we need the morph model and the relationship represented by CypherGrammar
        // statically with 'r'.
        $this->query->select('r', $parentNode, $this->relation);
        // Add morph mutation that will tell the parser about the property name on the Relationship that is holding
        // the class name of our morph model so that they can instantiate the correct one, and pass the relation
        // name as an indicator of the Node that has our morph attributes in the query.
        $this->query->addMutation($parentNode, $this->parent);
        $this->query->addEagerMorphMutation($this->relation);
        // Set the parent node's placeholder as the RETURN key.
        $this->query->getQuery()->from = array($parentNode);
        // Build the MATCH ()<-[]-() Cypher clause.
        $this->query->matchMorphOut($this->parent, $this->relation, $this->foreignKey, $this->parent->{$this->foreignKey});
        // Add WHERE clause over the parent node's matching keys [values...].
        $this->query->whereIn($this->foreignKey, $this->getKeys($models));
    }
1178258
def _add_constraints(self, relation):
        
        expression = relation.expression
        pairs = []
        for value_set in expression.value_sets():
            ind, val = zip(*((self._variables[variable], float(value))
                             for variable, value in value_set))
            pairs.append(cp.SparsePair(ind=ind, val=val))

        names = [next(self._constr_names) for _ in pairs]

        sense = self.CONSTR_SENSE_MAP[relation.sense]
        self._cp.linear_constraints.add(
            names=names, lin_expr=pairs,
            senses=tuple(repeat(sense, len(pairs))),
            rhs=tuple(repeat(float(-expression.offset), len(pairs))))

        return names
1110837
def add_query_kwargs(kwargs, visitor, constraints, index):
    
    (query_const, filter_const) = constraints.remove_index(index)
    kwargs["key_condition_expr"] = query_const.build(visitor)
    if filter_const:
        kwargs["filter"] = filter_const.build(visitor)
    if index.name != "TABLE":
        kwargs["index"] = index.name
1091008
def add_eager_constraints(self, models):
        
        super(MorphToMany, self).add_eager_constraints(models)

        self._query.where('%s.%s' % (self._table, self._morph_type), self._morph_class)
228926
public function addConstraints()
    {
        $parentTable = $this->parent->getTable();

        $this->setJoin();

        if (static::$constraints) {
            $this->query->where($parentTable.'.'.$this->firstKey, '=', $this->farParent->getKey());
        }
    }
5672
public function withCount( $relations )
	{
		if ( is_null( $this->query->columns ) )
		{
			$this->query->select( ['*'] );
		}

		$relations = is_array( $relations ) ? $relations : func_get_args();

		foreach ( $this->parseWithRelations( $relations ) as $name => $constraints )
		{
			// Here we will get the relationship count query and prepare to add it to the main query
			// as a sub-select. First, we'll get the "has" query and use that to get the relation
			// count query. We will normalize the relation name then append _count as the name.
			$relation = $this->getHasRelationQuery( $name );

			$query = $relation->getRelationCountQuery( $relation->getRelated()->newQuery(), $this );

			$query->callScope( $constraints );

			$query->mergeModelDefinedRelationConstraints( $relation->getQuery() );

			$this->selectSub( $query->toBase(), snake_case( $name ) . '_count' );
		}

		return $this;
	}
389676
def add_constraints(self):
        
        if self._constraints:
            super(MorphOneOrMany, self).add_constraints()

            self._query.where(self._morph_type, self._morph_name)
109150
public function withCount($relations) {
        if (empty($relations)) {
            return $this;
        }

        if (empty($this->selects)) {
            $this->select();
        }

        $relations = is_array($relations) ? $relations : func_get_args();

        foreach ($this->parseWithRelations($relations) as $name => $constraints) {
            // First we will determine if the name has been aliased using an "as" clause on the name
            // and if it has we will extract the actual relationship name and the desired name of
            // the resulting column. This allows multiple counts on the same relationship name.
            $segments = explode(' ', $name);

            $alias = null;

            if (count($segments) == 3 && strtolower($segments[1]) == 'as') {
                list($name, $alias) = [$segments[0], $segments[2]];
            }

            $relation = $this->getRelationWithoutConstraints($name);

            // Here we will get the relationship count query and prepare to add it to the main query
            // as a sub-select. First, we'll get the "has" query and use that to get the relation
            // count query. We will normalize the relation name then append _count as the name.
            $query = $relation->getRelationExistenceCountQuery(
                $relation->getRelated()->query(), $this
            );

            // Finally we will add the proper result column alias to the query and run the subselect
            // statement against the query builder. Then we will return the builder instance back
            // to the developer for further constraint chaining that needs to take place on it.
            $column = $alias ?: strtolower($name.'_count');

            $this->selectSub($query->getSql(), $column);
        }

        return $this;
    }
1027332
def get_relation_count_query(self, query, parent):
        
        if parent.get_query().from__ == query.get_query().from__:
            return self.get_relation_count_query_for_self_join(query, parent)

        self._set_join(query)

        return super(BelongsToMany, self).get_relation_count_query(query, parent)
449211
def add(self, relation):
        
        r = Relation(relation)
        key = r.relation_key[0]
        if key not in self.relations:
            self.relations[key] = r
            self.relations[r.relation_key[1]]= r
702325
public function getRelationCountQuery(Query $query, Query $parent)
    {
        if ($parent->getQuery()->from == $query->getQuery()->from) {
            return $this->getRelationCountQueryForSelfJoin($query, $parent);
        }

        $this->setJoin($query);

        return parent::getRelationCountQuery($query, $parent);
    }
66266
def count_children(cls, resource_id, db_session=None, *args, **kwargs):
        
        query = db_session.query(cls.model.resource_id)
        query = query.filter(cls.model.parent_id == resource_id)
        return query.count()
1057332
def add_eager_constraints(self, models):
        
        super(MorphOneOrMany, self).add_eager_constraints(models)

        self._query.where(self._morph_type, self._morph_class)
1161155
public function getRelationCountQuery(Builder $query, Builder $parent)
	{
		if ($parent->getQuery()->from == $query->getQuery()->from)
		{
			return $this->getRelationCountQueryForSelfRelation($query, $parent);
		}

		return parent::getRelationCountQuery($query, $parent);
	}
441371
def add(self, parent, obj_type, **attributes):
        
        return self.ixnCommand('add', parent.obj_ref(), obj_type, get_args_pairs(attributes))