Skip to content

Commit

Permalink
Merge pull request #7776 from cakephp/5.x-cleanup
Browse files Browse the repository at this point in the history
Consistent aliasing for assocs.
  • Loading branch information
dereuromark authored Nov 29, 2023
2 parents d791f5c + d208841 commit f6e09ce
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions en/orm/associations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -186,26 +186,26 @@ If you want to break different addresses into multiple associations, you can do
{
public function initialize(array $config): void
{
$this->hasOne('HomeAddress', [
$this->hasOne('HomeAddresses', [
'className' => 'Addresses'
])
->setProperty('home_address')
->setConditions(['HomeAddress.label' => 'Home'])
->setConditions(['HomeAddresses.label' => 'Home'])
->setDependent(true);

$this->hasOne('WorkAddress', [
$this->hasOne('WorkAddresses', [
'className' => 'Addresses'
])
->setProperty('work_address')
->setConditions(['WorkAddress.label' => 'Work'])
->setConditions(['WorkAddresses.label' => 'Work'])
->setDependent(true);
}
}

.. note::

If a column is shared by multiple hasOne associations, you must qualify it with the association alias.
In the above example, the 'label' column is qualified with the 'HomeAddress' and 'WorkAddress' aliases.
In the above example, the 'label' column is qualified with the 'HomeAddresses' and 'WorkAddresses' aliases.

Possible keys for hasOne association arrays include:

Expand Down

0 comments on commit f6e09ce

Please sign in to comment.