Generic belongsto relation

The actual associations that result from my example code would in the Alarms controller would be:

$this->Alarms->XMachines;
$this->Alarms->YMachines;
$this->Alarms->ZMachines;

From the other sides (the machine side) all the associations could be named the same:

$this->YMachines->Alarms; //etc

You could of course abstract your references to the associated table. Something like this, based on my previous example associations:


foreach (['XMachine', 'YMachine', 'ZMachine'] as $machine ) {
   $this->Alarms->$machine->someMethod();
}

Still, I’m completely mystified about what the use case might be for such a structure :slight_smile:

Later

Ah! Possibly your ids are UUIDs not integers.