Skip to content
Permalink
Browse files

Use the registryAlias when setting entity source.

Refs #7187
  • Loading branch information...
markstory committed Aug 6, 2015
1 parent 3953c1e commit 0c3f904dd635edc72a5d15538b459fe0f65601a8
Showing with 28 additions and 3 deletions.
  1. +2 −2 src/ORM/ResultSet.php
  2. +26 −1 tests/TestCase/ORM/ResultSetTest.php
@@ -507,7 +507,7 @@ protected function _groupResult($row)
)
);
if ($this->_hydrate) {
$options['source'] = $alias;
$options['source'] = $matching['instance']->registryAlias();
$entity = new $matching['entityClass']($results['_matchingData'][$alias], $options);
$entity->clean();
$results['_matchingData'][$alias] = $entity;
@@ -546,7 +546,7 @@ protected function _groupResult($row)
}
$target = $instance->target();
$options['source'] = $target->alias();
$options['source'] = $target->registryAlias();
unset($presentAliases[$alias]);
if ($assoc['canBeJoined']) {
@@ -15,6 +15,7 @@
namespace Cake\Test\TestCase\ORM;
use Cake\Core\Configure;
use Cake\Core\Plugin;
use Cake\Datasource\ConnectionManager;
use Cake\ORM\Entity;
use Cake\ORM\Query;
@@ -29,7 +30,7 @@
class ResultSetTest extends TestCase
{
public $fixtures = ['core.articles', 'core.comments'];
public $fixtures = ['core.authors', 'core.articles', 'core.comments'];
/**
* setup
@@ -343,4 +344,28 @@ public function testFetchMissingDefaultAlias()
$result->valid();
$data = $result->current();
}
/**
* Test that associations have source() correctly set.
*
* @return void
*/
public function testSourceOnContainAssociations()
{
Plugin::load('TestPlugin');
$comments = TableRegistry::get('TestPlugin.Comments');
$comments->belongsTo('Authors', [
'className' => 'TestPlugin.Authors',
'foreignKey' => 'user_id'
]);
$result = $comments->find()->contain(['Authors'])->first();
$this->assertEquals('TestPlugin.Comments', $result->source());
$this->assertEquals('TestPlugin.Authors', $result->author->source());
$result = $comments->find()->matching('Authors', function ($q) {
return $q->where(['Authors.id' => 1]);
})->first();
$this->assertEquals('TestPlugin.Comments', $result->source());
$this->assertEquals('TestPlugin.Authors', $result->_matchingData['Authors']->source());
}
}

0 comments on commit 0c3f904

Please sign in to comment.
You can’t perform that action at this time.