Browse Source

Demonstrate that there isn't alias-confusion

When dealing with overlapping table aliases
AD7six 11 years ago
parent
commit
9d1e8a3918
1 changed files with 23 additions and 0 deletions
  1. 23 0
      tests/TestCase/ORM/TableTest.php

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

@@ -16,6 +16,7 @@ namespace Cake\Test\TestCase\ORM;
 
 use ArrayObject;
 use Cake\Core\Configure;
+use Cake\Core\Plugin;
 use Cake\Database\Expression\OrderByExpression;
 use Cake\Database\Expression\QueryExpression;
 use Cake\Database\TypeMap;
@@ -520,6 +521,28 @@ class TableTest extends TestCase
     }
 
     /**
+     * Should a dupicate short-named association be defined, the earlier
+     * association will be inaccessible via the __get method
+     *
+     * @return void
+     */
+    public function testHasManyPluginOverlap()
+    {
+        TableRegistry::get('Comments');
+        Plugin::load('TestPlugin');
+
+        $table = new Table(['table' => 'authors']);
+
+        $table->hasOne('Comments');
+        $comments = $table->Comments->target();
+        $this->assertInstanceOf('Cake\ORM\Table', $comments);
+
+        $table->hasMany('TestPlugin.Comments');
+        $comments = $table->Comments->target();
+        $this->assertInstanceOf('TestPlugin\Model\Table\CommentsTable', $comments);
+    }
+
+    /**
      * Tests that BelongsToMany() creates and configures correctly the association
      *
      * @return void