Skip to content

Commit 9d1e8a3

Browse files
committed
Demonstrate that there isn't alias-confusion
When dealing with overlapping table aliases
1 parent 6b02321 commit 9d1e8a3

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/TestCase/ORM/TableTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
use ArrayObject;
1818
use Cake\Core\Configure;
19+
use Cake\Core\Plugin;
1920
use Cake\Database\Expression\OrderByExpression;
2021
use Cake\Database\Expression\QueryExpression;
2122
use Cake\Database\TypeMap;
@@ -519,6 +520,28 @@ public function testHasMany()
519520
$this->assertSame($table, $hasMany->source());
520521
}
521522

523+
/**
524+
* Should a dupicate short-named association be defined, the earlier
525+
* association will be inaccessible via the __get method
526+
*
527+
* @return void
528+
*/
529+
public function testHasManyPluginOverlap()
530+
{
531+
TableRegistry::get('Comments');
532+
Plugin::load('TestPlugin');
533+
534+
$table = new Table(['table' => 'authors']);
535+
536+
$table->hasOne('Comments');
537+
$comments = $table->Comments->target();
538+
$this->assertInstanceOf('Cake\ORM\Table', $comments);
539+
540+
$table->hasMany('TestPlugin.Comments');
541+
$comments = $table->Comments->target();
542+
$this->assertInstanceOf('TestPlugin\Model\Table\CommentsTable', $comments);
543+
}
544+
522545
/**
523546
* Tests that BelongsToMany() creates and configures correctly the association
524547
*

0 commit comments

Comments
 (0)