Browse Source

Include joint table columns in default type maps

Including the joint table columns in the default type maps will allow
joint table types to be mapped correctly without developers having to
declare the types.

Refs #6775
Mark Story 10 years ago
parent
commit
322335848d
2 changed files with 11 additions and 5 deletions
  1. 1 0
      src/ORM/Association/BelongsToMany.php
  2. 10 5
      tests/TestCase/ORM/QueryRegressionTest.php

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

@@ -941,6 +941,7 @@ class BelongsToMany extends Association
 
         $assoc = $this->target()->association($name);
         $query
+            ->addDefaultTypes($assoc->target())
             ->join($matching + $joins, [], true)
             ->autoFields($query->clause('select') === [])
             ->select($query->aliasFields((array)$assoc->foreignKey(), $name));

+ 10 - 5
tests/TestCase/ORM/QueryRegressionTest.php

@@ -905,6 +905,11 @@ class QueryRegressionTest extends TestCase
         );
     }
 
+    /**
+     * Test that contain queries map types correctly.
+     *
+     * @return void
+     */
     public function testBooleanConditionsInContain()
     {
         $table = TableRegistry::get('Articles');
@@ -915,13 +920,13 @@ class QueryRegressionTest extends TestCase
         ]);
         $query = $table->find()
             ->contain(['Tags' => function ($q) {
-                return $q->where(['SpecialTags.highlighted' => false]);
+                return $q->where(['SpecialTags.highlighted_time >' => new Time('2014-06-01 00:00:00')]);
             }])
-            ->order(['Articles.id' => 'ASC']);
+            ->where(['Articles.id' => 2]);
 
         $result = $query->first();
-        $this->assertEquals(1, $result->id);
-        $this->assertNotEmpty($result->tags);
-        $this->assertNotEmpty($result->tags[0]->_joinData);
+        $this->assertEquals(2, $result->id);
+        $this->assertNotEmpty($result->tags, 'Missing tags');
+        $this->assertNotEmpty($result->tags[0]->_joinData, 'Missing join data');
     }
 }