BelongsTo
in package
Defines a belongs-to relationship (many-to-one).
Example: A Post belongs to a User
Attributes
- #[Attribute]
- \Attribute::TARGET_PROPERTY
Table of Contents
Properties
- $foreignKey : string|null
- $ownerKey : string|null
- $relatedModel : string
Methods
- __construct() : mixed
- Constructor
Properties
$foreignKey read-only
public
string|null
$foreignKey
= null
$ownerKey read-only
public
string|null
$ownerKey
= 'id'
$relatedModel read-only
public
string
$relatedModel
Methods
__construct()
Constructor
public
__construct(string $relatedModel[, string|null $foreignKey = null ][, string|null $ownerKey = 'id' ]) : mixed
Parameters
- $relatedModel : string
-
The fully qualified class name of the related model
- $foreignKey : string|null = null
-
The foreign key column name (default: {relation}_id)
- $ownerKey : string|null = 'id'
-
The owner key column name (default: id)