Skip to content

Commit

Permalink
Fix Server issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Sep 12, 2025
1 parent 4f22a75 commit 5d1b04f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
32 changes: 26 additions & 6 deletions app/src/Lib/Traits/PluggableModelTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,35 @@ protected function setPluginRelations() {
continue;
}

// Derive association alias from "Plugin.Model"
[$pluginName, $modelAlias] = explode('.', $m->plugin, 2);

// Skip if alias would clash with this table alias or already exists
if ($modelAlias === $this->getAlias()) {
// Avoid "Association alias 'X' is already set."
$this->llog('debug', "Skipping association for plugin '{$m->plugin}' due to alias clash with table alias '{$this->getAlias()}'");
continue;
}

if ($this->associations()->has($modelAlias)) {
// Association already defined elsewhere; don't rebind
$this->llog('debug', "Association '{$modelAlias}' already exists, skipping plugin relation '{$m->plugin}'");
continue;
}

// In general, a model with a "plugin" field has a 1-1 relation
// with the instantiated plugin configuration. eg: One instance
// of a Server has exactly one SqlServer associated with it.
$this->hasOne($m->plugin)
->setDependent(true)
->setCascadeCallbacks(true);

// Cache the list of entry points that we found
$this->_pluginModels[] = $m->plugin;
// Bind by alias and explicitly set the className.
$this->hasOne($modelAlias)
->setClassName($m->plugin)
->setDependent(true)
->setCascadeCallbacks(true);

// Cache the list of entry points that we found (avoid duplicates)
if (!in_array($m->plugin, $this->_pluginModels, true)) {
$this->_pluginModels[] = $m->plugin;
}
}

// isArtifactTable() might not be the exact right test here...
Expand Down
5 changes: 1 addition & 4 deletions app/src/Model/Table/ServersTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ public function initialize(array $config): void {
$this->hasMany('Pipelines')
->setForeignKey('match_server_id');

// XXX Note this will bind to (eg) CoreServer but not (eg) SqlProvisioner
// As of Cake 5 this is causing errors with the Servers alias already being set,
// it's not clear that we need this anymore?
// $this->setPluginRelations();
$this->setPluginRelations();

$this->setDisplayField('description');

Expand Down

0 comments on commit 5d1b04f

Please sign in to comment.