|
|
@@ -36,7 +36,7 @@ class BelongsToTest extends TestCase
|
|
|
*
|
|
|
* @var array
|
|
|
*/
|
|
|
- public $fixtures = ['core.articles', 'core.comments'];
|
|
|
+ public $fixtures = ['core.articles', 'core.comments', 'core.authors'];
|
|
|
|
|
|
/**
|
|
|
* Don't autoload fixtures as most tests uses mocks.
|
|
|
@@ -103,6 +103,28 @@ class BelongsToTest extends TestCase
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Tests that the alias set on associations is actually on the Entity
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testCustomAlias()
|
|
|
+ {
|
|
|
+ $table = TableRegistry::get('Articles', [
|
|
|
+ 'className' => 'TestPlugin.Articles'
|
|
|
+ ]);
|
|
|
+ $table->addAssociations([
|
|
|
+ 'belongsTo' => [
|
|
|
+ 'FooAuthors' => ['className' => 'TestPlugin.Authors', 'foreignKey' => 'author_id']
|
|
|
+ ]
|
|
|
+ ]);
|
|
|
+ $article = $table->find()->contain(['FooAuthors'])->first();
|
|
|
+
|
|
|
+ $this->assertTrue(isset($article->foo_author));
|
|
|
+ $this->assertEquals($article->foo_author->name, 'mariano');
|
|
|
+ $this->assertNull($article->Authors);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Tests that the correct join and fields are attached to a query depending on
|
|
|
* the association config
|
|
|
*
|