Browse Source

Fixing entity source after recent changes

Jose Lorenzo Rodriguez 11 years ago
parent
commit
f044137152
2 changed files with 16 additions and 1 deletions
  1. 1 1
      src/ORM/Table.php
  2. 15 0
      tests/TestCase/ORM/TableTest.php

+ 1 - 1
src/ORM/Table.php

@@ -1872,7 +1872,7 @@ class Table implements RepositoryInterface, EventListenerInterface
     {
         if ($data === null) {
             $class = $this->entityClass();
-            $entity = new $class(['source' => $this->registryAlias()]);
+            $entity = new $class([], ['source' => $this->registryAlias()]);
             return $entity;
         }
         if (!isset($options['associated'])) {

+ 15 - 0
tests/TestCase/ORM/TableTest.php

@@ -3587,4 +3587,19 @@ class TableTest extends TestCase
         $this->assertEquals(1, $beforeDeleteCount);
         $this->assertEquals(1, $afterDeleteCount);
     }
+
+    /**
+     * Tests that calling newEntity() on a table sets the right source alias
+     *
+     * @return void
+     */
+    public function testEntitySource()
+    {
+        $table = TableRegistry::get('Articles');
+        $this->assertEquals('Articles', $table->newEntity()->source());
+
+        Plugin::load('TestPlugin');
+        $table = TableRegistry::get('TestPlugin.Comments');
+        $this->assertEquals('TestPlugin.Comments', $table->newEntity()->source());
+    }
 }