Cakephp 4 custom hasOne Associaton Condition

114 views Asked by At

I have those two tables:

Addresses:

id | member_id | label | ... | start | end | ...

and

Members:

id | firstname | ... | created | modified

Every member has many addresses during his life, and I need to track when he lived where. That's why I have a start and an end field in the address.

I'm working in Members Scope, select a few of them by other data and want to access their current address. This is the address with the highest start value, so i decided to add another association in the MembersTable.php called CurrentAddress.

This is my current Version:

    $this->hasOne('CurrentAddress', [
        'foreignKey' => 'member_id',
        'className' => 'Addresses',
        'conditions' => [
            
        ]
    ])
      ->setProperty('current_address')
      ->setDependent(true);

I played around and checked the cookbook, but i can't get a condition to find the highest start date of the Address to work.

Could anyone show me the correct definition for "Highest start date of this users addresses"

Thanks in advance!

0

There are 0 answers