BelongsToRelation
extends Relation
in package
Implements belongs-to relationship logic.
Table of Contents
Properties
- $_parent : Model
- $_pdo : PDO
- $_relatedModel : string
- $_foreignKey : string
- $_ownerKey : string
Methods
- __construct() : mixed
- Constructor
- eagerLoad() : void
- Eager load relations for multiple models.
- getRelatedModel() : string
- Get the related model class name.
- handleDependent() : void
- Handle dependent cascade when parent is destroyed.
- load() : Model|null
- Load the related model.
Properties
$_parent
protected
Model
$_parent
$_pdo
protected
PDO
$_pdo
$_relatedModel
protected
string
$_relatedModel
$_foreignKey
private
string
$_foreignKey
$_ownerKey
private
string
$_ownerKey
Methods
__construct()
Constructor
public
__construct(PDO $pdo, Model $parent, string $relatedModel, string $foreignKey[, string $ownerKey = 'id' ]) : mixed
Parameters
- $pdo : PDO
-
Database connection
- $parent : Model
-
Parent model instance
- $relatedModel : string
-
Related model class name
- $foreignKey : string
-
Foreign key column name
- $ownerKey : string = 'id'
-
Owner key column name
eagerLoad()
Eager load relations for multiple models.
public
eagerLoad(array<string|int, mixed> $models) : void
Parameters
- $models : array<string|int, mixed>
-
Array of parent models
getRelatedModel()
Get the related model class name.
public
getRelatedModel() : string
Return values
stringhandleDependent()
Handle dependent cascade when parent is destroyed.
public
handleDependent(DependentStrategy $strategy) : void
Note: BelongsTo relationships typically don't use dependent strategies since the child model doesn't "own" the parent model.
Parameters
- $strategy : DependentStrategy
load()
Load the related model.
public
load() : Model|null