Skip to content

Commit a7202ac

Browse files
committed
Fix restriction: "keys inside the array list must match" at \ClickHouseDB\Client::prepareInsertAssocBulk
1 parent f73f11a commit a7202ac

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/BaseModel.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ public static function prepareAndInsert($rows, $columns = [])
142142
*/
143143
public static function insertAssoc($rows)
144144
{
145+
$rows = array_values($rows);
146+
if (isset($rows[0]) && isset($rows[1])) {
147+
$keys = array_keys($rows[0]);
148+
foreach ($rows as &$row) {
149+
$row = array_replace(array_flip($keys), $row);
150+
}
151+
}
145152
return static::getClient()->insertAssocBulk((new static)->getTable(), $rows);
146153
}
147154

@@ -152,14 +159,8 @@ public static function insertAssoc($rows)
152159
*/
153160
public static function prepareAndInsertAssoc($rows)
154161
{
155-
$rows = array_values(array_map('static::prepareAssocFromRequest', $rows));
156-
if (isset($rows[0]) && isset($rows[1])) {
157-
$keys = array_keys($rows[0]);
158-
foreach ($rows as &$row) {
159-
$row = array_replace(array_flip($keys), $row);
160-
}
161-
}
162-
return static::getClient()->insertAssocBulk((new static)->getTable(), $rows);
162+
$rows = array_map('static::prepareAssocFromRequest', $rows);
163+
return static::insertAssoc($rows);
163164
}
164165

165166
/**

0 commit comments

Comments
 (0)