LMongo\Eloquent\Model::belongsTo PHP Method

belongsTo() public method

Define an inverse one-to-one or many relationship.
public belongsTo ( string $related, string $foreignKey = null ) : BelongsTo
$related string
$foreignKey string
return LMongo\Eloquent\Relations\BelongsTo
    public function belongsTo($related, $foreignKey = null)
    {
        list(, $caller) = debug_backtrace(false);
        // 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.
        $relation = $caller['function'];
        if (is_null($foreignKey)) {
            $foreignKey = snake_case($relation) . '_id';
        }
        // 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.
        $instance = new $related();
        $query = $instance->newQuery();
        return new BelongsTo($query, $this, $foreignKey, $relation);
    }
Model