79393289

Date: 2025-01-28 09:29:37
Score: 1
Natty:
Report link

As documented here I can use 'foreignKey' instead of ->setForeignKey.

If I use ->setForeignKey it will invoke the frameworks conventions which means that if I want to associate with the contact archives table the belongsTo must be declared like:

$this->belongsTo('ContactArchives', [
    'setForeignKey' => 'contact_archive_id'
]);

But I only have contact_id in the contact archives table which means I must bypass the conventions and use the below to access the active and archives contacts table:

Active Contacts Table

$this->belongsTo('Contacts', [
    'setForeignKey' => 'contact_id'
]);

Archive Contacts Table

$this->belongsTo('ContactArchives', [
    'foreignKey' => 'contact_id'
]);
Reasons:
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Zenzs