Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

change the structure of find result array

  • Loading branch information...
commit e77674a1a42a213f84a2b70477aa6c223e7d68b5 1 parent 923a3bb
@ichikaway ichikaway authored
Showing with 9 additions and 3 deletions.
  1. +9 −3 models/datasources/mongodb_source.php
View
12 models/datasources/mongodb_source.php
@@ -1049,21 +1049,26 @@ public function read(&$Model, $query = array(), $recursive = null) {
);
$hasManyResult = $linkModel->find('all', $params);
+
if(!empty($hasManyResult)) {
//aggregate retrieving data using array key(foreigin key _id)
$hasManyResultSet = array();
foreach($hasManyResult as $key => $val) {
- $hasManyResultSet[ $val[$linkModel->alias][$assocData['foreignKey']] ][] = $val;
+ $foreignKey = $val[$linkModel->alias][$assocData['foreignKey']];
+ if(!empty($foreignKey)) {
+ $hasManyResultSet[$foreignKey][] = $val[$linkModel->alias];
+ }
}
//set relational retrieving data to return data
foreach($return as $key => $val) {
if(!empty($hasManyResultSet[ $val[$Model->alias][$Model->primaryKey] ])) {
- $return[$key][$linkModel->alias] = $hasManyResultSet[ $val[$Model->alias][$Model->primaryKey] ];
+ $return[$key][$Model->alias][$linkModel->alias] = $hasManyResultSet[ $val[$Model->alias][$Model->primaryKey] ];
} else {
- $return[$key][$linkModel->alias] = array();
+ $return[$key][$Model->alias][$linkModel->alias] = array();
}
}
+
}
break;
@@ -1123,6 +1128,7 @@ public function read(&$Model, $query = array(), $recursive = null) {
}
}
break;
+
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.