Skip to content

Commit

Permalink
reset m2m keys when duplicated are removed
Browse files Browse the repository at this point in the history
  • Loading branch information
wellingguzman committed Sep 27, 2016
1 parent c7e60bc commit 06c7d9f
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions api/core/Directus/Db/TableGateway/RelationalTableGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,7 @@ public function loadToManyRelationships($entry, $aliasColumns)
$entry[$this->primaryKeyFieldName]);
$noDuplicates = isset($alias['options']['no_duplicates']) ? $alias['options']['no_duplicates'] : 0;
// @todo: better way to handle this.
// @TODO: fetch uniques/non-duplicates entries
if ($noDuplicates) {
$uniquesID = [];
foreach ($foreign_data['rows'] as $index => $row) {
Expand All @@ -842,6 +843,34 @@ public function loadToManyRelationships($entry, $aliasColumns)
}
}
unset($uniquesID);
// =========================================================
// Reset keys
// ---------------------------------------------------------
// This prevent json output using numeric ids as key
// Ex:
// {
// rows: {
// "1": {
// data: {id: 1}
// },
// "3" {
// data: {id: 2}
// }
// }
// }
// Instead of:
// {
// rows: [
// {
// data: {id: 1}
// },
// {
// data: {id: 2}
// }
// ]
// }
// =========================================================
$foreign_data['rows'] = array_values($foreign_data['rows']);
}
break;
case 'ONETOMANY':
Expand Down

0 comments on commit 06c7d9f

Please sign in to comment.