mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Refactoring Model::__validateWithModels. Should be slightly faster as loops are smaller.
This commit is contained in:
parent
a490e249fa
commit
4ac29963a8
1 changed files with 21 additions and 18 deletions
|
@ -2513,26 +2513,29 @@ class Model extends Overloadable {
|
||||||
*/
|
*/
|
||||||
function __validateWithModels($options) {
|
function __validateWithModels($options) {
|
||||||
$valid = true;
|
$valid = true;
|
||||||
foreach ($this->data as $assoc => $data) {
|
foreach ($this->hasAndBelongsToMany as $assoc => $association) {
|
||||||
if (isset($this->hasAndBelongsToMany[$assoc]) && !empty($this->hasAndBelongsToMany[$assoc]['with'])) {
|
if (empty($association['with']) || !isset($this->data[$assoc])) {
|
||||||
list($join) = $this->joinModel($this->hasAndBelongsToMany[$assoc]['with']);
|
continue;
|
||||||
$newData = array();
|
}
|
||||||
foreach ((array)$data as $row) {
|
list($join) = $this->joinModel($this->hasAndBelongsToMany[$assoc]['with']);
|
||||||
if (isset($row[$this->hasAndBelongsToMany[$assoc]['associationForeignKey']])) {
|
$data = $this->data[$assoc];
|
||||||
$newData[] = $row;
|
|
||||||
} elseif (isset($row[$join]) && isset($row[$join][$this->hasAndBelongsToMany[$assoc]['associationForeignKey']])) {
|
$newData = array();
|
||||||
$newData[] = $row[$join];
|
foreach ((array)$data as $row) {
|
||||||
}
|
if (isset($row[$this->hasAndBelongsToMany[$assoc]['associationForeignKey']])) {
|
||||||
}
|
$newData[] = $row;
|
||||||
if (empty($newData)) {
|
} elseif (isset($row[$join]) && isset($row[$join][$this->hasAndBelongsToMany[$assoc]['associationForeignKey']])) {
|
||||||
continue;
|
$newData[] = $row[$join];
|
||||||
}
|
|
||||||
foreach ($newData as $data) {
|
|
||||||
$data[$this->hasAndBelongsToMany[$assoc]['foreignKey']] = $this->id;
|
|
||||||
$this->{$join}->create($data);
|
|
||||||
$valid = ($valid && $this->{$join}->validates($options));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (empty($newData)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
foreach ($newData as $data) {
|
||||||
|
$data[$this->hasAndBelongsToMany[$assoc]['foreignKey']] = $this->id;
|
||||||
|
$this->{$join}->create($data);
|
||||||
|
$valid = ($valid && $this->{$join}->validates($options));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $valid;
|
return $valid;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue