Skip to content

Commit

Permalink
Fix restriction: "keys inside the array list must match" at \ClickHou…
Browse files Browse the repository at this point in the history
…seDB\Client::prepareInsertAssocBulk
  • Loading branch information
glushkovds committed Dec 18, 2020
1 parent f73f11a commit a7202ac
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ public static function prepareAndInsert($rows, $columns = [])
*/
public static function insertAssoc($rows)
{
$rows = array_values($rows);
if (isset($rows[0]) && isset($rows[1])) {
$keys = array_keys($rows[0]);
foreach ($rows as &$row) {
$row = array_replace(array_flip($keys), $row);
}
}
return static::getClient()->insertAssocBulk((new static)->getTable(), $rows);
}

Expand All @@ -152,14 +159,8 @@ public static function insertAssoc($rows)
*/
public static function prepareAndInsertAssoc($rows)
{
$rows = array_values(array_map('static::prepareAssocFromRequest', $rows));
if (isset($rows[0]) && isset($rows[1])) {
$keys = array_keys($rows[0]);
foreach ($rows as &$row) {
$row = array_replace(array_flip($keys), $row);
}
}
return static::getClient()->insertAssocBulk((new static)->getTable(), $rows);
$rows = array_map('static::prepareAssocFromRequest', $rows);
return static::insertAssoc($rows);
}

/**
Expand Down

0 comments on commit a7202ac

Please sign in to comment.