Include relations into the result
@class Model
@method include
@param {array} includes - array of relation names to include
@or
@param {object} includes - for nested includes use objects

@see Model.exec

@return {Model}
964485
function() {
    const Utils = this.definition.store.utils
    const self = this.chain()

    const includes = Utils.toIncludesList(Utils.args(arguments))
    const existingIncludes = self.getInternal('includes') || []
    const existingMap = {}

    existingIncludes.forEach(function(inc) {
      existingMap[inc.relation] = inc
    })

    includes.forEach(function(inc) {
      const relation = self.definition.relations[inc.relation]
      if (relation) {
        if (relation.through) inc.through = true
        if (existingMap[inc.relation]) return // ignore duplicated includes

        self.addInternal('includes', inc)
      } else {
        throw new Error(
          'Can\'t find relation "' +
            inc.relation +
            '" for ' +
            self.definition.modelName
        )
      }
    })

    return self
  }
1369179
protected function includeDefaultIncludes($model, $data)
    {
        // Create an return array
        $returnData = [];

        // If we have default includes
        if ( ! empty( $this->defaultIncludes ) ) {

            // Loop through all includes
            foreach ($this->defaultIncludes as $include) {

                // Add the new data
                $returnData[ $include ] = $this->includeByName( $include, $model );

            }

        }

        // Return data
        return array_merge( $data, $returnData );
    }
795102
public function include($includes)
	{
		$model = $this;

		(function() use ($includes, $model): void
		{
			$this->including($includes)->loadIncludes([$model]);
		})->bindTo($this->builder(), Query::class)();

		return $this;
	}
326602
function include(partial, cb) {
    cb((params.partials && params.partials[partial]) ?
      params.partials[partial] :
      '[error] partial ' + partial + ' does not exist');
  }
887785
function(options){
            var cleanOptions = this.parseOptions(options),
                excludes = _.clone(this.privateFields),
                includeExludes = [];

            // If any includes are passed in through the options clean up the
            // default excluded fields. A type can have some excluded fields by
            // default and if the user overrides this then we need to clean up the query.
            if(options && options.include){
                _.each(options.include, function(include){
                    //If the include matches an existing exclude then remove it from the
                    //excludes and also from the includes (you can't mix them)
                    excludes = _.remove(excludes, function(o){
                        if(o === include){
                            cleanOptions.include = _.remove(cleanOptions.include, function(i){
                                return i !== include;
                            });
                        }

                        return o !== include;
                    });

                });
            }

            includeExludes = _.union(cleanOptions.include,
                this.parseExclusion(cleanOptions.exclude),
                this.parseExclusion(excludes)
            );

            return includeExludes.join(' ');
        }
1134821
def with_(self, *relations):
        
        if not relations:
            return self

        eagers = self._parse_relations(list(relations))

        self._eager_load.update(eagers)

        return self
136040
function(name, options) {
    const self = this
    const utils = this.store.utils

    options.preInitialize = function() {
      options.relation = options.relation || name
      options.from = []
      options.to = []

      if (!Array.isArray(options.through)) options.through = [options.through]

      // add the last relation name for easier looping
      options.through.push(options.relation)

      var tmpDefinition = self
      var targetRelation
      var relation

      // find the last relation of the through list
      for (var index = 0; index < options.through.length; index++) {
        const relationName = options.through[index]

        if (!tmpDefinition)
          throw new Error(
            "Can't create a `through` relation through a `has` or `belongs_to_polymorphic` relation'"
          )

        relation = tmpDefinition.relations[relationName]
        if (!relation)
          throw new Error(
            "Can't find relation '" +
              relationName +
              "' on model " +
              tmpDefinition.modelName
          )
        if (relation === options) throw new Error('Relation loop detected!')
        if (relation.type === 'has')
          throw new Error(
            "Can't create a `through` relation through a `has` relation'"
          )

        relation.init()

        // in case we have a nested through relation
        if (relation.through) {
          options.through.splice.apply(
            options.through,
            [index, 1].concat(relation.through)
          )
          index += relation.through.length - 1
        }

        targetRelation = relation
        if (relation.model) tmpDefinition = relation.model.definition
      }

      options.targetRelation = targetRelation
      if (relation.model) options.model = relation.model
    }

    options.rawGetter = function() {
      var result = this.relations[name]

      if (result === undefined) {
        if (this['_' + options.through[0]] === undefined) return // through relation is not loaded, so we can't filter it

        result = options.filterCache(this)
        options.setResult(this, result)
      }

      if (typeof options.transform === 'function') {
        return options.transform(result)
      }
      return result
    }

    // does not load anything, but we use it to set the original includes
    options.loadFromConditions = function(
      parentCollection,
      parentConditions,
      include
    ) {
      const includes = {}
      var tmpIncludes = includes

      // convert the array of through relations to an object.
      // e.g. ['a', 'b'] => {a: {b: {}}}
      options.through.forEach(function(relationName, index) {
        tmpIncludes[relationName] = {}

        // add sub includes
        if (index === options.through.length - 1 && include.children) {
          tmpIncludes[relationName] = include.children
        }

        tmpIncludes = tmpIncludes[relationName]
      })

      if (include.conditions) tmpIncludes.$conditions = include.conditions
      if (options.scope) tmpIncludes.$scope = options.scope
      if (include.args)
        tmpIncludes.$args = Array.isArray(include.args)
          ? include.args
          : [include.args]

      // include `through` relations instead
      parentCollection.include(includes)
    }

    options.loadFromRecords = function(parentCollection, include) {
      return Promise.resolve([]) // no need to load anything. `loadFromConditions` (via include) or `loadWithCollection` will handle all loading!
    }

    options.loadWithCollection = function(collection) {
      const parent = collection.getInternal('relation_to') || self.model.new(collection.getInternal('cloned_relation_to'))
      const chain = self.relations[options.through[0]].collection(parent)

      utils.assignInternals(chain, collection)
      collection.runScopes() // run scopes on original connection to check if it should return raw results

      const includes = {}
      const asRaw = collection.getInternal('as_raw')
      const joinOrInclude = asRaw ? 'join' : 'include'
      var tmpIncludes = includes

      // convert the array of through relations to an object.
      options.through.slice(1).forEach(function(relationName, index) {
        tmpIncludes[relationName] = {}
        tmpIncludes = tmpIncludes[relationName]
      })

      if (options.scope) tmpIncludes.$scope = options.scope
      
      chain.setInternal('through', options.through)
      if(asRaw) chain.clearInternal('relation')
      
      return chain[joinOrInclude](includes).then(function(result) {        
        if (asRaw) return result
        return options.filterCache(parent)
      })
    }

    options.filterCache = function(parentRecord) {
      var tmpRecords = [parentRecord]
      options.through.forEach(function(relationName) {
        const tmp = []
        tmpRecords.forEach(function(record) {
          const child = record['_' + relationName]

          if (!child) return

          if (Array.isArray(child)) tmp.push.apply(tmp, child)
          else tmp.push(child)
        })
        tmpRecords = tmp
      })
      const throughRecords = tmpRecords

      if (options.model) {
        const chain = options.model.chain()

        chain.add(throughRecords) // add all child records
        chain.setInternal('relation', options) // add the parent relation of this collection
        chain.setInternal('relation_to', parentRecord) // + the parent record
        chain._resolved() // set this collection as existing (all records fetched from the datastore!)

        if (options.type === 'has_one') return chain[0]
        return chain
      }

      if (options.type === 'has_one') return throughRecords[0]
      return throughRecords
    }

    options.collection = function(parentRecord) {
      if (options.targetRelation) {
        const chain = options.targetRelation.collection(parentRecord)
        chain.setInternal('relation', options) // add the parent relation of this collection
        chain.setInternal('relation_to', parentRecord) // + the parent record
        return chain
      }
      throw new Error(
        'You need to implement your own `collection` function! (relation: ' +
          name +
          ')'
      )
    }

    options.add = function(parent, record) {
      if (options.through.length > 2)
        throw new Error(
          "Doesn't not work with a has many through over " +
            options.through.length +
            ' relations!'
        )

      // add records to the other relation
      const newRecord = {}
      newRecord[options.through[1]] = record
      parent[options.through[0]].add(newRecord)
    }

    // clear all records
    options.clear = function(parent, collection) {
      if (options.through.length > 2)
        throw new Error(
          "Doesn't not work with a has many through over " +
            options.through.length +
            ' relations!'
        )

      const through = options.through[0]
      var throughRel = parent.relations[through]
      if (!throughRel) {
        throughRel = parent[through]
        self.relations[through].setResult(parent, throughRel)
      }
      throughRel.clear()
    }

    options.afterSave = function(parent, saveOptions) {
      // will be handled by the real relations
    }

    return options
  }
260166
public boolean execInsert(D6Model[] modelObjects) {
    final D6Inex includeExcludeColumnNames = null;
    return execInsert(modelObjects, includeExcludeColumnNames, false);
  }
706618
def relations_of(self, target, include_object=False):
        '''  '''
        if include_object:
            _ = self._execute('''
                select relations.name, ob2.code from relations, objects as ob1, objects as ob2 where relations.src=ob1.id and ob2.id=relations.dst and ob1.code=?
            ''', (self.serialize(target),))
            for i in _:
                yield i[0], self.deserialize(i[1])
        else:

            _ = self._execute('''
                select distinct relations.name from relations, objects where relations.src=objects.id and objects.code=?
            ''', (self.serialize(target),))
            for i in _:
                yield i[0]
774611
function() {

        if ( !ModelUtil.instance && !getContext('modelUtil') ) {
            self.models             = self.models || {}; // used when getModel(modelName) is called
            self.entities           = {};
            self.entitiesCollection = {}; // used when getEntity(entityName) is called - handles entity relations
            self.files              = {};
            ModelUtil.instance      = self;

            setContext('modelUtil', ModelUtil.instance);

            return self
        } else {
            //if (!ModelUtil.instance) {
            //    ModelUtil.instance = getContext('modelUtil')
            //}
            //self = ModelUtil.instance;
            //ModelUtil.instance = getContext('modelUtil');
            //ModelUtil.instance = ModelUtil.instance || getContext('modelUtil');
            //self = merge(self, ModelUtil.instance, true);
            // return self
            return ModelUtil.instance || getContext('modelUtil')
        }
    }
325972
public function include($includes)
	{
		$items = $this->items;

		(function() use ($includes, $items): void
		{
			$this->including($includes)->loadIncludes($items);
		})->bindTo($this->items[0]->builder(), Query::class)();

		return $this;
	}
99341
public List<ENTITY> findIncludeColumns(Collection<String> includeColumns, Match... matches) {
        return findColumns(Arrays.asList(matches), includeColumns.toArray(new String[includeColumns.size()]));
    }
1206744
function _includeModel (include, mds, field, v) {
  if (include.length === 0) {
    include.push(_includeModelFactory.call(this, {}, mds, field, v))
  } else {
    let includeModel = _.find(include, m => m.model.name === mds[0])

    if (includeModel) {
      let md = mds.shift()

      if (mds.length === 0) {
        if (!includeModel.where) {
          includeModel.where = {}
        }

        _queryField2where.call(this, includeModel.where, field, v, md)
      } else {
        if (!includeModel.include) {
          includeModel.include = []
        }
        _includeModel.call(this, includeModel.include, mds, field, v)
      }
    } else {
      include.push(_includeModelFactory.call(this, {}, mds, field, v))
    }
  }
}
1297558
def relations_of(self, target, include_object=False):
        '''  '''
        relations = (target if isinstance(target, RamGraphDBNode) else self._get_item_node(target)).outgoing
        if include_object:
            for k in relations:
                for v in relations[k]:
                    if hasattr(v, 'obj'): # filter dead links
                        yield k, v.obj
        else:
            yield from relations
185659
protected function includes($includes)
    {
        $includes = \is_array($includes) ? $includes : \func_get_args();

        $this->includes = $includes;

        return $this;
    }
351132
public void _include(IncludeBuilderBase includes) {
        if (includes == null) {
            return;
        }

        if (includes.documentsToInclude != null) {
            for (String doc : includes.documentsToInclude) {
                documentIncludes.add(doc);
            }
        }

        _includeCounters(includes.alias, includes.countersToIncludeBySourcePath);
    }
633938
function parseRelations (data, relations, options) {
  var relationships = {}

  _.each(relations, function (relation, name) {
    var fkName = relation.keyTo

    // If relation is belongsTo then fk is the other way around
    if (utils.relationFkOnModelFrom(relation)) {
      fkName = relation.keyFrom
    }

    var pk = data[options.primaryKeyField]
    var fk = data[fkName]

    var toType = ''
    if (relation.polymorphic && utils.relationFkOnModelFrom(relation)) {
      var discriminator = relation.polymorphic.discriminator
      var model = options.app.models[data[discriminator]]
      toType = utils.pluralForModel(model)
    } else {
      toType = utils.pluralForModel(relation.modelTo)
    }

    // Relationship `links` should always be defined unless this is a
    // relationship request
    if (!options.isRelationshipRequest) {
      relationships[name] = {
        links: {
          related: options.host +
            options.restApiRoot +
            '/' +
            options.modelPath +
            '/' +
            pk +
            '/' +
            name
        }
      }
    }

    var relationship = null

    if (!_.isUndefined(fk) && relation.modelTo !== relation.modelFrom) {
      if (_.isArray(fk)) {
        relationship = makeRelations(toType, fk, options)
      } else {
        relationship = makeRelation(toType, fk, options)
      }
    }

    // No `data` key should be present unless there is actual relationship data.
    if (relationship) {
      relationships[name].data = relationship
    } else if (relation.type === 'belongsTo') {
      relationships[name].data = null
    }
  })

  return relationships
}