01.28
php
saved
hiromi2424
Note
changed function __saveMulti() of Model fot ticket #275
changed function __saveMulti() of Model fot ticket #275
- /**
- * Saves model hasAndBelongsToMany data to the database.
- *
- * @param array $joined Data to save
- * @param mixed $id ID of record in this model
- * @access private
- */
- function __saveMulti($joined, $id, &$db) {
- foreach ($joined as $assoc => $data) {
- $this->{$join}->_schema[$this->{$join}->primaryKey]['length'] == 36 && (
- $this->{$join}->_schema[$this->{$join}->primaryKey]['type'] === 'string' ||
- $this->{$join}->_schema[$this->{$join}->primaryKey]['type'] === 'binary'
- )
- );
- $primaryAdded = false;
- $db->name($this->hasAndBelongsToMany[$assoc]['foreignKey']),
- $db->name($this->hasAndBelongsToMany[$assoc]['associationForeignKey'])
- );
- $idField = $db->name($this->{$join}->primaryKey);
- $fields[] = $idField;
- $primaryAdded = true;
- }
- if ($this->hasAndBelongsToMany[$assoc]['unique']) {
- );
- 'conditions' => $conditions,
- 'fields' => $this->hasAndBelongsToMany[$assoc]['associationForeignKey']
- ));
- $associationForeignKey = "{$join}." . $this->hasAndBelongsToMany[$assoc]['associationForeignKey'];
- $newLink = null;
- $newLink = $row;
- continue;
- }
- $newLink = $row[$this->hasAndBelongsToMany[$assoc]['associationForeignKey']];
- continue;
- }
- $newLink = $row[$join][$this->hasAndBelongsToMany[$assoc]['associationForeignKey']];
- }
- if(!$newLink){
- continue;
- }
- $newLinks[] = $newLink;
- }
- $conditions[$associationForeignKey] = $toDeleteLinks;
- $db->delete($this->{$join}, $conditions);
- }
- }
- continue;
- }
- $db->value($id, $this->getColumnType($this->primaryKey)),
- $db->value($row)
- );
- if ($isUUID && $primaryAdded) {
- $values[] = $db->value(String::uuid());
- }
- $newValues[] = "({$values})";
- continue;
- }
- $newData[] = $row;
- continue;
- }
- $newData[] = $row[$join];
- }
- }
- foreach ($newData as $data) {
- $data[$this->hasAndBelongsToMany[$assoc]['foreignKey']] = $id;
- $this->{$join}->create($data);
- $this->{$join}->save();
- }
- }
- $db->insertMulti($this->{$join}, $fields, $newValues);
- }
- }
- }
- }
Parsed in 0.262 seconds, using GeSHi 1.0.7.14