Skip to content
This repository
Browse code

fixes #5710, HABTM - constraining unique ids, but removing non-unique

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8217 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information...
commit f2b7a26be8d125fc46fb4f816ae3b0fd5e6e53bf 1 parent 45a51ed
authored July 03, 2009
5  cake/libs/model/datasources/dbo_source.php
@@ -858,11 +858,8 @@ function queryAssociation(&$model, &$linkModel, $type, $association, $assocData,
858 858
 
859 859
 						foreach ($fetch as $j => $data) {
860 860
 							if (
861  
-								(isset($data[$with]) && $data[$with][$foreignKey] === $row[$model->alias][$model->primaryKey]) &&
862  
-								(!in_array($data[$with][$joinKeys[1]], $uniqueIds))
  861
+								(isset($data[$with]) && $data[$with][$foreignKey] === $row[$model->alias][$model->primaryKey])
863 862
 							) {
864  
-								$uniqueIds[] = $data[$with][$joinKeys[1]];
865  
-
866 863
 								if ($habtmFieldsCount <= 2) {
867 864
 									unset($data[$with]);
868 865
 								}
37  cake/tests/cases/libs/model/model.test.php
@@ -13022,5 +13022,42 @@ function testPkInHabtmLinkModelArticleB() {
13022 13022
 		$TestModel2 =& new ArticleB();
13023 13023
 		$this->assertEqual($TestModel2->ArticlesTag->primaryKey, 'article_id');
13024 13024
 	}
  13025
+/**
  13026
+ * testFetchingNonUniqueFKJoinTableRecords()
  13027
+ *
  13028
+ * Tests if the results are properly returned in the case there are non-unique FK's
  13029
+ * in the join table but another fields value is different. For example:
  13030
+ * something_id | something_else_id | doomed = 1
  13031
+ * something_id | something_else_id | doomed = 0
  13032
+ * Should return both records and not just one.
  13033
+ *
  13034
+ * @access public
  13035
+ * @return void
  13036
+ */
  13037
+	function testFetchingNonUniqueFKJoinTableRecords() {
  13038
+		$this->loadFixtures('Something', 'SomethingElse', 'JoinThing');
  13039
+		$Something = new Something();
  13040
+
  13041
+		$joinThingData = array(
  13042
+			'JoinThing' => array(
  13043
+				'something_id' => 1,
  13044
+				'something_else_id' => 2,
  13045
+				'doomed' => '0',
  13046
+				'created' => '2007-03-18 10:39:23',
  13047
+				'updated' => '2007-03-18 10:41:31'
  13048
+			)
  13049
+		);
  13050
+		$Something->JoinThing->create($joinThingData);
  13051
+		$Something->JoinThing->save();
  13052
+
  13053
+		$result = $Something->JoinThing->find('all', array('conditions' => array('something_else_id' => 2)));
  13054
+		$this->assertEqual($result[0]['JoinThing']['doomed'], 1);
  13055
+		$this->assertEqual($result[1]['JoinThing']['doomed'], 0);
  13056
+
  13057
+		$result = $Something->find('first');
  13058
+		$this->assertEqual(count($result['SomethingElse']), 2);
  13059
+		$this->assertEqual($result['SomethingElse'][0]['JoinThing']['doomed'], 1);
  13060
+		$this->assertEqual($result['SomethingElse'][1]['JoinThing']['doomed'], 0);
  13061
+	}
13025 13062
 }
13026 13063
 ?>

0 notes on commit f2b7a26

Please sign in to comment.
Something went wrong with that request. Please try again.