diff --git a/app/availableplugins/ApiConnector/src/Model/Table/ApiSourcesTable.php b/app/availableplugins/ApiConnector/src/Model/Table/ApiSourcesTable.php index 8b555443c..0cb1f6d72 100644 --- a/app/availableplugins/ApiConnector/src/Model/Table/ApiSourcesTable.php +++ b/app/availableplugins/ApiConnector/src/Model/Table/ApiSourcesTable.php @@ -63,9 +63,6 @@ public function initialize(array $config): void { $this->belongsTo('ExternalIdentitySources'); $this->belongsTo('ApiUsers'); - $this->hasMany('ApiConnector.ApiSourceEndpoints') - ->setDependent(true) - ->setCascadeCallbacks(true); $this->hasMany('ApiConnector.ApiSourceRecords') ->setDependent(true) ->setCascadeCallbacks(true); diff --git a/app/src/Command/CloneCommand.php b/app/src/Command/CloneCommand.php index 73befe30d..63a343a26 100644 --- a/app/src/Command/CloneCommand.php +++ b/app/src/Command/CloneCommand.php @@ -401,7 +401,7 @@ protected function cloneEntity( } $this->io->out($original->uuid . ": Cloning " . $className . " " . $id - . " from CO " . $sourceCoId . " to CO " . $targetCoId); + . " from CO " . $sourceCoId . " to CO " . $targetCoId . " using $targetDataSource target"); // Clone any predecessor objects first. There is a default implementations in // ClonableTrait that should cover most scenarios, so we don't need to check diff --git a/app/src/Lib/Util/TableUtilities.php b/app/src/Lib/Util/TableUtilities.php index 6e5d4084c..66165888c 100644 --- a/app/src/Lib/Util/TableUtilities.php +++ b/app/src/Lib/Util/TableUtilities.php @@ -139,7 +139,10 @@ public static function getTableWithDataSource( if(!$aTargetTable->hasAssociation($targetAlias)) { $m->$aType($targetAlias) ->setClassName($className) - ->setForeignKey(StringUtilities::tableToForeignKey($target)) + // For the relation (eg) RemoteMatchServers hasMany RemoteMatchServerAttributes + // we need to set the foreign key to match_server_id (ie what the data model has + // for match_server_attributes to fk back to match_servers) + ->setForeignKey(StringUtilities::classNameToForeignKey(StringUtilities::pluginModel($tableName))) ->setCascadeCallbacks(true) ->setTarget($aTargetTable); // Unlike PluggableTrait we don't setDependent(), it's not clear if we need to... diff --git a/app/src/Model/Table/CousTable.php b/app/src/Model/Table/CousTable.php index 105031672..b670ce33f 100644 --- a/app/src/Model/Table/CousTable.php +++ b/app/src/Model/Table/CousTable.php @@ -175,6 +175,11 @@ public function buildRules(RulesChecker $rules): RulesChecker { */ public function localAfterSave(\Cake\Event\EventInterface $event, \Cake\Datasource\EntityInterface $entity, \ArrayObject $options) { + if(isset($options['clone']) && $options['clone']) { + // If we're in the middle of cloning, don't run setup or addDefaults + return; + } + if(!empty($entity->id)) { if($entity->isNew()) { // Run setup for new COU