Browse Source

Adding test for loading belongsTo with loadInto when having
composite primary keys

Jose Lorenzo Rodriguez 10 years ago
parent
commit
b7a7106b84
1 changed files with 21 additions and 0 deletions
  1. 21 0
      tests/TestCase/ORM/CompositeKeysTest.php

+ 21 - 0
tests/TestCase/ORM/CompositeKeysTest.php

@@ -695,6 +695,27 @@ class CompositeKeyTest extends TestCase
 
     /**
      * Tets that loadInto() is capable of handling composite primary keys
+     * when loading belongsTo assocaitions
+     *
+     * @return void
+     */
+    public function testLoadIntoWithBelongsTo()
+    {
+        $table = TableRegistry::get('SiteArticles');
+        $table->belongsTo('SiteAuthors', [
+            'foreignKey' => ['author_id', 'site_id'],
+        ]);
+
+        $author = $table->get([2, 2]);
+        $result = $table->loadInto($author, ['SiteAuthors']);
+        $this->assertSame($author, $result);
+
+        $expected = $table->get([2, 2], ['contain' => ['SiteAuthors']]);
+        $this->assertEquals($expected, $result);
+    }
+
+    /**
+     * Tets that loadInto() is capable of handling composite primary keys
      * when loading into multiple entities
      *
      * @return void