diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 3f4df483cd4..7c770ac8f41 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -1437,15 +1437,17 @@ protected function _fetchHasAndBelongsToMany(Model $Model, $query, $ids, $associ } /** - * Merge the results of hasMany relations. + * Merge the results of 'hasMany' associations. + * + * Note: this function also deals with the formatting of the data. * * @param array $resultSet Data to merge into. - * @param array $merge Data to merge. + * @param array $assocResultSet Data to merge. * @param string $association Name of Model being merged. * @param Model $Model Model being merged onto. * @return void */ - protected function _mergeHasMany(&$resultSet, $merge, $association, $Model) { + protected function _mergeHasMany(&$resultSet, $assocResultSet, $association, Model $Model) { $modelAlias = $Model->alias; $primaryKey = $Model->primaryKey; $foreignKey = $Model->hasMany[$association]['foreignKey']; @@ -1458,7 +1460,7 @@ protected function _mergeHasMany(&$resultSet, $merge, $association, $Model) { $resultPrimaryKey = $result[$modelAlias][$primaryKey]; $merged = array(); - foreach ($merge as $data) { + foreach ($assocResultSet as $data) { if ($resultPrimaryKey !== $data[$association][$foreignKey]) { continue; } @@ -1637,7 +1639,7 @@ public function buildAssociationQuery(Model $Model, $queryData) { * @param boolean $external Whether or not the association query is on an external datasource. * @return mixed * String representing a query. - * True. when $external is false and association $type is 'hasOne' or 'belongsTo'. + * True, when $external is false and association $type is 'hasOne' or 'belongsTo'. */ public function generateAssociationQuery(Model $Model, Model $LinkModel, $type, $association, $assocData, &$queryData, $external) { $assocData = $this->_scrubQueryData($assocData);