Set the constraints for an eager load of the relation.

        :type models: list
177824
def add_eager_constraints(self, models):
        
        self._models = Collection.make(models)
        self._build_dictionary(models)
1287667
def eager_load(properties)
      unless properties.empty? || key.nil? || collection.nil?
        # set an initial value to prevent recursive lazy loads
        properties.each { |property| property.set!(self, nil) }

        collection.reload(:fields => properties)
      end

      self
    end
545373
def _set_seo_models(self, value):
        
        seo_models = []
        for model_name in value:
            if "." in model_name:
                app_label, model_name = model_name.split(".", 1)
                model = models.get_model(app_label, model_name)
                if model:
                    seo_models.append(model)
            else:
                app = models.get_app(model_name)
                if app:
                    seo_models.extend(models.get_models(app))
    
        self.seo_models = seo_models
1233994
def models_from_model(model, include_related=False, exclude=None):
    ''''''
    if exclude is None:
        exclude = set()
    if model and model not in exclude:
        exclude.add(model)
        if isinstance(model, ModelType) and not model._meta.abstract:
            yield model
            if include_related:
                exclude.add(model)
                for field in model._meta.fields:
                    if hasattr(field, 'relmodel'):
                        through = getattr(field, 'through', None)
                        for rmodel in (field.relmodel, field.model, through):
                            for m in models_from_model(
                                    rmodel, include_related=include_related,
                                    exclude=exclude):
                                yield m
                for manytomany in model._meta.manytomany:
                    related = getattr(model, manytomany)
                    for m in models_from_model(related.model,
                                               include_related=include_related,
                                               exclude=exclude):
                        yield m
        elif not isinstance(model, ModelType) and isclass(model):
            # This is a class which is not o ModelType
            yield model
1149386
def _add_constraints(self, relation):
        

        expression = relation.expression
        constr_count = sum(True for _ in expression.value_sets())
        if constr_count == 0:
            return []

        row_indices = count(swiglpk.glp_add_rows(self._p, constr_count))

        names = []
        for i, value_set in zip(row_indices, expression.value_sets()):
            value_set = list(value_set)
            var_indices = swiglpk.intArray(1 + len(value_set))
            var_values = swiglpk.doubleArray(1 + len(value_set))
            for j, (variable, coeff) in enumerate(value_set):
                var_indices[1 + j] = self._variables[variable]
                var_values[1 + j] = float(coeff)

            swiglpk.glp_set_mat_row(
                self._p, i, len(value_set), var_indices, var_values)

            if relation.sense == RelationSense.Greater:
                swiglpk.glp_set_row_bnds(
                    self._p, i, swiglpk.GLP_LO, -float(expression.offset), 0)
            elif relation.sense == RelationSense.Less:
                swiglpk.glp_set_row_bnds(
                    self._p, i, swiglpk.GLP_UP, 0, -float(expression.offset))
            else:
                swiglpk.glp_set_row_bnds(
                    self._p, i, swiglpk.GLP_FX, -float(expression.offset), 0)

            names.append(i)

        self._do_presolve = True

        return names
917596
def init_relation(self, models, relation):
        
        for model in models:
            model.set_relation(relation, Result(None, self, model))

        return models
276297
def set_list_predicates(self):
        
        results = self.rml.query("""
                SELECT DISTINCT ?subj_class ?list_field
                {
                    ?bn rr:datatype rdf:List .
                    ?bn rr:predicate ?list_field .
                    ?s ?p ?bn .
                    ?s rr:subjectMap ?sm_bn .
                    ?sm_bn rr:class ?subj_class .
                }""")
        list_preds = [(Uri(row[0]).sparql, Uri(row[1]).sparql)
                      for row in results]
        array_fields = {}
        for tup in list_preds:
            try:
                array_fields[tup[0]].append(tup[1])
            except KeyError:
                array_fields[tup[0]] = [tup[1]]
        self.array_fields = array_fields
1257071
public function addConstraints()
    {
        if (static::$constraints)
        {
            $this->query->where($this->foreignKey, '=', $this->getParentKey());

            $this->query->whereNotNull($this->foreignKey);

            $this->query->where($this->rootKey, '=', $this->getRootKey());

            $this->query->whereNotNull($this->rootKey);

        }
    }
560403
def _constraint_names(self, model, column_names=None, unique=None,
                          primary_key=None, index=None, foreign_key=None,
                          check=None):
        
        column_names = list(column_names) if column_names else None
        with self.connection.cursor() as cursor:
            constraints = get_constraints(cursor, model._meta.db_table)
        result = []
        for name, infodict in constraints.items():
            if column_names is None or column_names == infodict['columns']:
                if unique is not None and infodict['unique'] != unique:
                    continue
                if primary_key is not None and infodict['primary_key'] != primary_key:
                    continue
                if index is not None and infodict['index'] != index:
                    continue
                if check is not None and infodict['check'] != check:
                    continue
                if foreign_key is not None and not infodict['foreign_key']:
                    continue
                result.append(name)

        return result
392454
def set_model(self, model):
        
        self._model = model

        self._query.from_(model.get_table())

        return self
172062
def set_relation_many_to_many(self, obj, field_name, objs):
        ""
        relation = getattr(obj, field_name)
        if hasattr(relation, 'set'):
            relation.set(objs) # Django 2.x
        else:
            setattr(obj, field_name, objs)
891198
public function addConstraints()
    {
        if (static::$constraints) {
            // For belongs to relationships, which are essentially the inverse of has one
            // or has many relationships, we need to actually query on the primary key
            // of the related models matching on the foreign key that's on a parent.
            $table = $this->related->getTable();

            if (is_array($this->ownerKey)) { //Check for multi-columns relationship
                $childAttributes = $this->child->attributesToArray();
                foreach ($this->ownerKey as $index => $key) {
                    if (array_key_exists($this->foreignKey[$index], $childAttributes)) {
                        $this->query->where($table.'.'.$key, '=', $this->child->{$this->foreignKey[$index]});
                    }
                }
            } else {
                $this->query->where($table.'.'.$this->ownerKey, '=', $this->child->{$this->foreignKey});
            }
        }
    }
945708
def init_relation(self, models, relation):
        
        for model in models:
            model.set_relation(
                relation, Result(self._related.new_collection(), self, model)
            )

        return models
891926
public function addConstraints()
    {
        if (static::$constraints) {
            $this->query->where($this->foreignKey, '=', $this->getParentKey());

            $this->query->whereNotNull($this->foreignKey);
        }
    }
946566
public function addConstraints()
	{
		$parentTable = $this->parent->getTable();

		$localValue = $this->farParent[$this->localKey];

		$this->setJoin();

		if (static::$constraints) {
			$this->query->where($parentTable.'.'.$this->firstKey, '=', $localValue);
		}
	}
716070
def _nested_relations(self, relation):
        
        nested = {}

        for name, constraints in self._eager_load.items():
            if self._is_nested(name, relation):
                nested[name[len(relation + ".") :]] = constraints

        return nested
428990
public function addConstraints()
    {
        $this->performJoins();

        if (static::$constraints) {
            $localValue = $this->parent[$this->getFirstForeignKeyName()];

            $this->query->where($this->getQualifiedFirstLocalKeyName(), '=', $localValue);
        }
    }