fix stupid json unpacking bug turning indexed array to object

pull/35/head
Ondřej Hruška 6 years ago
parent f6109b5d4a
commit f42e80cc5d
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 4
      app/Models/Proposal.php
  2. 4
      app/Tables/Column.php

@ -137,10 +137,10 @@ class Proposal extends BaseModel
'proposal_id' => $this->getKey(), 'proposal_id' => $this->getKey(),
'note' => $changeset->note, 'note' => $changeset->note,
'row_count' => 0, // Will be set later when we are sure about the row count 'row_count' => 0, // Will be set later when we are sure about the row count
'columns' => array_filter(array_map(function(Column $c) { 'columns' => array_values(array_filter(array_map(function(Column $c) {
if ($c->toRemove) return null; if ($c->toRemove) return null;
return $c->toArray(false); return $c->toArray(false);
}, $columns)), }, $columns))),
]); ]);
$newRevision->save(); // this gives it an ID, needed to associate rows $newRevision->save(); // this gives it an ID, needed to associate rows

@ -103,12 +103,12 @@ class Column implements JsonSerializable, Arrayable
public static function columnsFromJson($columns) public static function columnsFromJson($columns)
{ {
if (is_string($columns)) { if (is_string($columns)) {
$columns = json_decode($columns); $columns = json_decode($columns, true);
} }
return array_map(function ($x) { return array_map(function ($x) {
return new Column($x); return new Column($x);
}, $columns); }, array_values((array)$columns));
} }
/** /**

Loading…
Cancel
Save