Skip to content

Commit

Permalink
Pass the locator to AssociationCollection.
Browse files Browse the repository at this point in the history
  • Loading branch information
robertpustulka committed Sep 19, 2017
1 parent 8e7e10a commit 535f99f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ORM/AssociationCollection.php
Expand Up @@ -16,6 +16,7 @@

use ArrayIterator;
use Cake\Datasource\EntityInterface;
use Cake\ORM\Locator\LocatorAwareTrait;
use InvalidArgumentException;
use IteratorAggregate;

Expand All @@ -29,6 +30,7 @@ class AssociationCollection implements IteratorAggregate
{

use AssociationsNormalizerTrait;
use LocatorAwareTrait;

/**
* Stored associations
Expand Down
6 changes: 6 additions & 0 deletions src/ORM/Locator/TableLocator.php
Expand Up @@ -16,6 +16,7 @@

use Cake\Core\App;
use Cake\Datasource\ConnectionManager;
use Cake\ORM\AssociationCollection;
use Cake\ORM\Table;
use Cake\Utility\Inflector;
use RuntimeException;
Expand Down Expand Up @@ -211,6 +212,11 @@ public function get($alias, array $options = [])
}
$options['connection'] = ConnectionManager::get($connectionName);
}
if (empty($options['associations'])) {
$associations = new AssociationCollection();
$associations->setTableLocator($this);
$options['associations'] = $associations;
}

$options['registryAlias'] = $alias;
$this->_instances[$alias] = $this->_create($options);
Expand Down
2 changes: 2 additions & 0 deletions tests/TestCase/ORM/Locator/TableLocatorTest.php
Expand Up @@ -164,6 +164,8 @@ public function testGet()
$result2 = $this->_locator->get('Articles');
$this->assertSame($result, $result2);
$this->assertEquals('my_articles', $result->table());

$this->assertSame($this->_locator, $result->associations()->getTableLocator());
}

/**
Expand Down

0 comments on commit 535f99f

Please sign in to comment.