Define a has-many-deep relationship.

@param  string  $related
@param  array  $through
@param  array  $foreignKeys
@param  array  $localKeys
@return \Staudenmeir\EloquentHasManyDeep\HasManyDeep
548815
public function hasManyDeep($related, array $through, array $foreignKeys = [], array $localKeys = [])
    {
        return $this->newHasManyDeep(...$this->hasOneOrManyDeep($related, $through, $foreignKeys, $localKeys));
    }
18955
public function setPivotKeys($foreignKey, $relatedKey)
    {
        $this->foreignKey = $foreignKey;

        $this->relatedKey = $relatedKey;

        return $this;
    }
268945
public function belongsToMany(string $related, ?string $primary_key = null, ?string $foreign_key = null)
    {
        $relatedModel = app()->make($related);
        $local_key = $local_key ?? $this->getKey();
        // Make the table name singular and append ID to it
        // FIXME: Use a more reliable approach
        $foreign_key = $foreign_key ?? rtrim($relatedModel->getTable(), 's').'_id';
        return new BelongsToMany($relatedModel, $this, $primary_key, $foreign_key);
    }
877313
public function hasOne($related, $parentKey = null, $localKey = null)
    {
        $parentKey = $parentKey ?: $this->getParentKey();
        $localKey = $localKey ?: $this->getKeyName();

        $instance = new $related;

        $relation = new Relations\Relation($instance, $this, $parentKey, $localKey);

        return $relation->find($localKey);
    }
259098
public function hasManyThroughSeveral(array $relations, $foreignKey = null, $localKey = null)
    {
        $helpers = new Helpers($this);
        $currentRelation = current($relations);
        $related = $helpers->getClassNameFromCurrent($currentRelation, $relations);
        $firstRelation = new $related();

        $instance = $this->newRelatedInstance($related);
        $query = $instance
            ->newQuery()
            ->distinct()
            ->select($firstRelation->getTable().'.*');

        $joins = $helpers->getReverseJoinsRelations($relations, $localKey);
        foreach ($joins as $join) {
            $query->join($join['table'], $join['key'], '=', $join['foreign_key']);
        }

        $query->addSelect($join['select_key']);

        $key = $localKey ?? $this->getTable().'.'.$this->getKeyName();
        $value = $this->{$this->getKeyName()};

        $foreignKey = $foreignKey ?? $join['foreign_key'];

        $localKey = $localKey ?? $this->getKeyName();

        $query->where($key, $value);

        return new HasMany($query, $this, $foreignKey, $localKey);
    }
482769
function HasOne(model, related, foreignKey, localKey) {
        var _this = _super.call(this, model) /* istanbul ignore next */ || this;
        _this.related = _this.model.relation(related);
        _this.foreignKey = foreignKey;
        _this.localKey = localKey;
        return _this;
    }
1143708
public function hasMany($entity, string $related, string $foreignKey = null, string $localKey = null): HasMany
    {
        $foreignKey = $foreignKey ?: $this->getForeignKey();

        $relatedMapper = Manager::getInstance()->mapper($related);

        $localKey = $localKey ?: $this->getKeyName();

        // Add the relation to the definition in map
        list(, $caller) = debug_backtrace(false);
        $relation = $caller['function'];
        $this->relatedClasses[$relation] = $related;

        $this->addManyRelation($relation);
        $this->addForeignRelation($relation);

        return new HasMany($relatedMapper, $entity, $foreignKey, $localKey);
    }
298424
public function belongsTo(string $related, ?string $foreign_key = null, ?string $local_key = null)
    {
        $relatedModel = app()->make($related);
        $local_key = $local_key ?? $this->getKey();
        // Make the table name singular and append ID to it
        // FIXME: Use a more reliable approach
        $foreign_key = $foreign_key ?? rtrim($relatedModel->getTable(), 's').'_id';
        return new BelongsTo($relatedModel, $this, $foreign_key, $local_key);
    }
288507
public function injectRelation(ForeignKey $foreignKey)
    {
        foreach ($this->_relations as $_relation) {
            if ($_relation->getId() === $foreignKey->getId()) {
                return;
            }
        }
        $this->_relations[] = $foreignKey;
    }
884540
public function getForeignKeyFor(string $localColumn, string $relatedTableName, string $relatedColumn) : ForeignKey
    {
        foreach ($this->foreignKeys as $foreignKey) {
            if ($foreignKey->getLocalColumnNames() === [$localColumn] && $foreignKey->getReferencedTableName() === $relatedTableName && $foreignKey->getReferencedColumnNames() === [$relatedColumn]) {
                return $foreignKey;
            }
        }
        
        throw InvalidArgumentException::format('Cannot find matching foreign key');
    }
247441
public function belongsToMany($alias, $class, $junction, $foreignKey = null, $relatedKey = null, Closure $conditions = null) {
        $relation = (new ManyToMany($alias, $class))
            ->setJunction($junction)
            ->setPrimaryForeignKey($foreignKey)
            ->setRelatedForeignKey($relatedKey);

        if ($conditions) {
            $relation->setConditions($conditions);
        }

        return $this->addRelation($relation);
    }
1207686
public function manyToOne ($relatedTable, $relatedKey = null, $key = null, $relationIdentifier = null)
		{
			if (is_null($relationIdentifier)) {
				$relationIdentifier = $relatedTable;
			}

			$this->relations[$relationIdentifier] = new ManyToOne(
				$this,
				$this->schema->getTable($relatedTable, true),
				$key,
				$relatedKey
			);

			return $this;
		}
274466
public function belongsTo(Model $relatedModel, $foreignKey)
    {
        if ($relatedModel->isIgnored()) {
            return;
        }

        $this->relations->add(
            new Relations\BelongsTo($this, $relatedModel, $foreignKey)
        );
    }
94324
public function belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null)
    {
        // If no relation name was given, we will use this debug backtrace to extract
        // the calling method's name and use that as the relationship name as most
        // of the time this will be what we desire to use for the relationships.
        if (is_null($relation)) {
            list($current, $caller) = debug_backtrace(false, 2);

            $relation = $caller['function'];
        }

        $specialType = $this->getCmsSpecialRelationType($relation);

        // If no foreign key was supplied, we can use a backtrace to guess the proper
        // foreign key name by using the name of the relationship function, which
        // when combined with an "_id" should conventionally match the columns.
        if (is_null($foreignKey)) {
            if ($specialType === self::RELATION_TYPE_CATEGORY) {
                $foreignKey = config('pxlcms.relations.categories.keys.category');
            } else {
                $foreignKey = Str::snake($relation);
            }
        }

        // If the relation name is the same (casing aside) as the foreign key attribute,
        // we must make sure that the foreign key property is at least a key in the
        // attributes array. If it is not, there will be recursive lookup problems
        // where the attribute is never resolved and 'property does not exist' exceptions occur.
        if (    snake_case($relation) == $foreignKey
            &&  ! array_key_exists($foreignKey, $this->attributes)
        ) {
            $this->attributes[ $foreignKey ] = null;
        }

        /** @var Builder $belongsTo */
        $belongsTo = parent::belongsTo($related, $foreignKey, $otherKey, $relation);

        // category relation must be filtered by module id
        if ($specialType === self::RELATION_TYPE_CATEGORY) {
            $belongsTo->where(
                config('pxlcms.relations.categories.keys.module'),
                $this->getModuleNumber()
            );
        }

        return $belongsTo;
    }
1280254
public function hasOneDeep($related, array $through, array $foreignKeys = [], array $localKeys = [])
    {
        return $this->newHasOneDeep(...$this->hasOneOrManyDeep($related, $through, $foreignKeys, $localKeys));
    }
396452
public function hasMany($model, $foreignKey = '', $localKey = '')
    {
        // 记录当前关联信息
        $model      = $this->parseModel($model);
        $localKey   = $localKey ?: $this->getPk();
        $foreignKey = $foreignKey ?: $this->getForeignKey($this->name);

        return new HasMany($this, $model, $foreignKey, $localKey);
    }
924149
public function belongsTo($related, $foreignKey = null, $ownerKey = null, $relation = null)
    {
        if (is_array($foreignKey)) { //Check for multi-columns relationship
            $this->validateRelatedModel($related);
        }

        // If no relation name was given, we will use this debug backtrace to extract
        // the calling method's name and use that as the relationship name as most
        // of the time this will be what we desire to use for the relationships.
        if (is_null($relation)) {
            $relation = $this->guessBelongsToRelation();
        }

        $instance = $this->newRelatedInstance($related);

        // If no foreign key was supplied, we can use a backtrace to guess the proper
        // foreign key name by using the name of the relationship function, which
        // when combined with an "_id" should conventionally match the columns.
        if (is_null($foreignKey)) {
            $foreignKey = Str::snake($relation).'_'.$instance->getKeyName();
        }

        // Once we have the foreign key names, we'll just create a new Eloquent query
        // for the related models and returns the relationship instance which will
        // actually be responsible for retrieving and hydrating every relations.
        $ownerKey = $ownerKey ?: $instance->getKeyName();

        return new BelongsTo($instance->newQuery(), $this, $foreignKey, $ownerKey, $relation);
    }