Table: AdditionalParticipantValues
$this->setPrimaryKey(['addition_id', 'participant_id']);
$this->belongsTo('Participants', [
'foreignKey' => 'participant_id',
'joinType' => 'INNER'
]);
Table: Participants
// add Duplicatable behavior
$this->addBehavior('Duplicatable.Duplicatable', [
// table finder
'finder' => 'all',
// duplicate also items and their properties
'contain' => ['AdditionalParticipantValues', 'ParticipantAffiliations'],
'saveOptions' => ['checkRules' => false]
]);
$this->hasMany('AdditionalParticipantValues', [
'foreignKey' => 'participant_id'
]);
In the _modifyEntity, it attempts to unset the primary key of any associations. This will cause an Array to String exception when using a composite key (which is an array). As workaround, I added the following check in the _modifyEntity
if(is_array($object->getPrimaryKey())){ unset($entity->{$object->getPrimaryKey()[1]}); }else{ unset($entity->{$object->getPrimaryKey()}); }
It assumes that a composite key will always be made up of 2, and it also assumes that we always preserve the 1st key (and unsets the 2nd).
This achieves what I want i.e. the fields are saved with the correct ID's.
Table: AdditionalParticipantValues
$this->setPrimaryKey(['addition_id', 'participant_id']);
Table: Participants
// add Duplicatable behavior
$this->addBehavior('Duplicatable.Duplicatable', [
// table finder
'finder' => 'all',
// duplicate also items and their properties
'contain' => ['AdditionalParticipantValues', 'ParticipantAffiliations'],
'saveOptions' => ['checkRules' => false]
]);
In the _modifyEntity, it attempts to unset the primary key of any associations. This will cause an Array to String exception when using a composite key (which is an array). As workaround, I added the following check in the _modifyEntity
if(is_array($object->getPrimaryKey())){ unset($entity->{$object->getPrimaryKey()[1]}); }else{ unset($entity->{$object->getPrimaryKey()}); }It assumes that a composite key will always be made up of 2, and it also assumes that we always preserve the 1st key (and unsets the 2nd).
This achieves what I want i.e. the fields are saved with the correct ID's.