LMongo\Eloquent\Relations\BelongsTo::addEagerConstraints PHP Method

addEagerConstraints() public method

Set the constraints for an eager load of the relation.
public addEagerConstraints ( array $models ) : void
$models array
return void
    public function addEagerConstraints(array $models)
    {
        // We'll grab the primary key name of the related models since it could be set to
        // a non-standard name and not "id". We will then construct the constraint for
        // our eagerly loading query so it returns the proper models from execution.
        $key = $this->related->getKeyName();
        $value = $this->getEagerModelKeys($models);
        $value = array_map(function ($value) {
            return $value instanceof MongoID ? $value : new MongoID($value);
        }, $value);
        $this->query->whereIn($key, $value);
    }