Browse Source

Removing, for now, the join table information when using 'matching'

Hydrating the join table with matching presents several challenges,
revisit this commit upon the first bug report asking for the extra table
info :)
Jose Lorenzo Rodriguez 12 years ago
parent
commit
c41f40cdbb
2 changed files with 17 additions and 0 deletions
  1. 14 0
      src/ORM/Association/BelongsToMany.php
  2. 3 0
      src/ORM/ResultSet.php

+ 14 - 0
src/ORM/Association/BelongsToMany.php

@@ -34,6 +34,7 @@ class BelongsToMany extends Association {
 	use ExternalAssociationTrait {
 		_options as _externalOptions;
 		_addFilteringCondition as _addExternalConditions;
+		transformRow as protected _transformRow;
 	}
 
 /**
@@ -244,6 +245,19 @@ class BelongsToMany extends Association {
 	}
 
 /**
+ * Correctly nests a result row associated values into the correct array keys inside the
+ * source results.
+ *
+ * @param array $row
+ * @return array
+ */
+	public function transformRow($row) {
+		$row = $this->_transformRow($row);
+		unset($row[$this->junction()->alias()]);
+		return $row;
+	}
+
+/**
  * Get the relationship type.
  *
  * @return string

+ 3 - 0
src/ORM/ResultSet.php

@@ -398,6 +398,9 @@ class ResultSet implements Countable, Iterator, Serializable, JsonSerializable {
 		}
 
 		foreach($presentAliases as $alias => $present) {
+			if (!isset($results[$alias])) {
+				continue;
+			}
 			$results[$defaultAlias][$alias] = $results[$alias];
 		}