PHP Class Illuminate\Database\Eloquent\Relations\BelongsTo

Inheritance: extends Illuminate\Database\Eloquent\Relations\Relation
Show file Open project: illuminate/database Class Usage Examples

Protected Properties

Property Type Description
$foreignKey string The foreign key of the parent model.
$otherKey string The associated key on the parent model.
$relation string The name of the relationship.
$selfJoinCount integer The count of self joins.

Public Methods

Method Description
__construct ( Builder $query, Model $parent, string $foreignKey, string $otherKey, string $relation ) : void Create a new belongs to relationship instance.
addConstraints ( ) : void Set the base constraints on the relation query.
addEagerConstraints ( array $models ) : void Set the constraints for an eager load of the relation.
associate ( Model | integer $model ) : Model Associate the model instance to the given parent.
dissociate ( ) : Model Dissociate previously associated model from the given parent.
getForeignKey ( ) : string Get the foreign key of the relationship.
getOtherKey ( ) : string Get the associated key of the relationship.
getQualifiedForeignKey ( ) : string Get the fully qualified foreign key of the relationship.
getQualifiedOtherKeyName ( ) : string Get the fully qualified associated key of the relationship.
getRelation ( ) : string Get the name of the relationship.
getRelationCountHash ( ) : string Get a relationship join table hash.
getRelationQuery ( Builder $query, Builder $parent, array | mixed $columns = ['*'] ) : Builder Add the constraints for a relationship query.
getRelationQueryForSelfRelation ( Builder $query, Builder $parent, array | mixed $columns = ['*'] ) : Builder Add the constraints for a relationship query on the same table.
getResults ( ) : mixed Get the results of the relationship.
initRelation ( array $models, string $relation ) : array Initialize the relation on a set of models.
match ( array $models, Illuminate\Database\Eloquent\Collection $results, string $relation ) : array Match the eagerly loaded results to their parents.
update ( array $attributes ) : mixed Update the parent model on the relationship.

Protected Methods

Method Description
getEagerModelKeys ( array $models ) : array Gather the keys from an array of related models.

Method Details

__construct() public method

Create a new belongs to relationship instance.
public __construct ( Builder $query, Model $parent, string $foreignKey, string $otherKey, string $relation ) : void
$query Illuminate\Database\Eloquent\Builder
$parent Illuminate\Database\Eloquent\Model
$foreignKey string
$otherKey string
$relation string
return void

addConstraints() public method

Set the base constraints on the relation query.
public addConstraints ( ) : void
return void

addEagerConstraints() public method

Set the constraints for an eager load of the relation.
public addEagerConstraints ( array $models ) : void
$models array
return void

associate() public method

Associate the model instance to the given parent.
public associate ( Model | integer $model ) : Model
$model Illuminate\Database\Eloquent\Model | integer
return Illuminate\Database\Eloquent\Model

dissociate() public method

Dissociate previously associated model from the given parent.
public dissociate ( ) : Model
return Illuminate\Database\Eloquent\Model

getEagerModelKeys() protected method

Gather the keys from an array of related models.
protected getEagerModelKeys ( array $models ) : array
$models array
return array

getForeignKey() public method

Get the foreign key of the relationship.
public getForeignKey ( ) : string
return string

getOtherKey() public method

Get the associated key of the relationship.
public getOtherKey ( ) : string
return string

getQualifiedForeignKey() public method

Get the fully qualified foreign key of the relationship.
public getQualifiedForeignKey ( ) : string
return string

getQualifiedOtherKeyName() public method

Get the fully qualified associated key of the relationship.
public getQualifiedOtherKeyName ( ) : string
return string

getRelation() public method

Get the name of the relationship.
public getRelation ( ) : string
return string

getRelationCountHash() public method

Get a relationship join table hash.
public getRelationCountHash ( ) : string
return string

getRelationQuery() public method

Add the constraints for a relationship query.
public getRelationQuery ( Builder $query, Builder $parent, array | mixed $columns = ['*'] ) : Builder
$query Illuminate\Database\Eloquent\Builder
$parent Illuminate\Database\Eloquent\Builder
$columns array | mixed
return Illuminate\Database\Eloquent\Builder

getRelationQueryForSelfRelation() public method

Add the constraints for a relationship query on the same table.
public getRelationQueryForSelfRelation ( Builder $query, Builder $parent, array | mixed $columns = ['*'] ) : Builder
$query Illuminate\Database\Eloquent\Builder
$parent Illuminate\Database\Eloquent\Builder
$columns array | mixed
return Illuminate\Database\Eloquent\Builder

getResults() public method

Get the results of the relationship.
public getResults ( ) : mixed
return mixed

initRelation() public method

Initialize the relation on a set of models.
public initRelation ( array $models, string $relation ) : array
$models array
$relation string
return array

match() public method

Match the eagerly loaded results to their parents.
public match ( array $models, Illuminate\Database\Eloquent\Collection $results, string $relation ) : array
$models array
$results Illuminate\Database\Eloquent\Collection
$relation string
return array

update() public method

Update the parent model on the relationship.
public update ( array $attributes ) : mixed
$attributes array
return mixed

Property Details

$foreignKey protected property

The foreign key of the parent model.
protected string $foreignKey
return string

$otherKey protected property

The associated key on the parent model.
protected string $otherKey
return string

$relation protected property

The name of the relationship.
protected string $relation
return string

$selfJoinCount protected static property

The count of self joins.
protected static int $selfJoinCount
return integer