1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137 |
/**
* 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']];
} elseif (isset($row[$join]) && isset($row[$join][$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;
} elseif (isset($row[$join]) && isset($row[$join][$this->hasAndBelongsToMany[$assoc]['associationForeignKey']])) {
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);
}
}
}
}
|
