mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Use the correct datasource when saving multiple model
This commit is contained in:
parent
144b556d1f
commit
fd07b961d4
1 changed files with 12 additions and 4 deletions
|
@ -1688,6 +1688,14 @@ class Model extends Object {
|
|||
list($join) = $this->joinModel($this->hasAndBelongsToMany[$assoc]['with']);
|
||||
|
||||
$keyInfo = $this->{$join}->schema($this->{$join}->primaryKey);
|
||||
if ($with = $this->hasAndBelongsToMany[$assoc]['with']) {
|
||||
$withModel = is_array($with) ? key($with) : $with;
|
||||
list($pluginName, $withModel) = pluginSplit($withModel);
|
||||
$dbMulti = $this->{$withModel}->getDataSource();
|
||||
} else {
|
||||
$dbMulti = $db;
|
||||
}
|
||||
|
||||
$isUUID = !empty($this->{$join}->primaryKey) && (
|
||||
$keyInfo['length'] == 36 && (
|
||||
$keyInfo['type'] === 'string' ||
|
||||
|
@ -1699,8 +1707,8 @@ class Model extends Object {
|
|||
$primaryAdded = false;
|
||||
|
||||
$fields = array(
|
||||
$db->name($this->hasAndBelongsToMany[$assoc]['foreignKey']),
|
||||
$db->name($this->hasAndBelongsToMany[$assoc]['associationForeignKey'])
|
||||
$dbMulti->name($this->hasAndBelongsToMany[$assoc]['foreignKey']),
|
||||
$dbMulti->name($this->hasAndBelongsToMany[$assoc]['associationForeignKey'])
|
||||
);
|
||||
|
||||
$idField = $db->name($this->{$join}->primaryKey);
|
||||
|
@ -1741,7 +1749,7 @@ class Model extends Object {
|
|||
$oldLinks = Set::extract($links, "{n}.{$associationForeignKey}");
|
||||
if (!empty($oldLinks)) {
|
||||
$conditions[$associationForeignKey] = $oldLinks;
|
||||
$db->delete($this->{$join}, $conditions);
|
||||
$dbMulti->delete($this->{$join}, $conditions);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1754,7 +1762,7 @@ class Model extends Object {
|
|||
}
|
||||
|
||||
if (!empty($newValues)) {
|
||||
$db->insertMulti($this->{$join}, $fields, $newValues);
|
||||
$dbMulti->insertMulti($this->{$join}, $fields, $newValues);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue