Permalink
Browse files

Adding Association::find() to proxy it to the target table

  • Loading branch information...
lorenzo committed Dec 18, 2013
1 parent 411093e commit 3acadff4b38c85ac0d8d705d895915cd8395b114
View
@@ -430,6 +430,22 @@ public function type() {
return self::ONE_TO_ONE;
}
/**
* Proxies the finding operation to the target table's find method
* and modifies the query accordingly based of this association
* configuration
*
* @param string $type
* @param array $options options for query
* @see \Cake\ORM\Table::find()
* @return \Cake\ORM\Query
*/
public function find($type, $options = []) {
return $this->target()
->find($type, $options)
->where($this->conditions());
}
/**
* Returns a single or multiple conditions to be appended to the generated join
* clause for getting the results on the target table. If false is returned then
@@ -174,15 +174,14 @@ protected function _resultInjector($fetchQuery, $resultMap) {
protected function _buildQuery($options) {
$target = $this->target();
$alias = $target->alias();
$options['conditions'] = array_merge($this->conditions(), $options['conditions']);
$key = $this->_linkField($options);
$filter = $options['keys'];
if ($options['strategy'] === parent::STRATEGY_SUBQUERY) {
$filter = $this->_buildSubquery($options['query'], $key);
}
$fetchQuery = $target
$fetchQuery = $this
->find('all')
->where($options['conditions'])
->hydrate($options['query']->hydrate());
@@ -398,9 +398,12 @@ public function testEagerLoaderWithDefaults() {
])
->will($this->returnSelf());
$query->expects($this->once())->method('where')
$query->expects($this->at(0))->method('where')
->with(['Tags.name' => 'foo'])
->will($this->returnValue($query));
$query->expects($this->at(1))->method('where')
->with([])
->will($this->returnValue($query));
$query->expects($this->once())->method('order')
->with(['id' => 'ASC'])
@@ -452,11 +455,12 @@ public function testEagerLoaderWithOverrides() {
])
->will($this->returnSelf());
$query->expects($this->once())->method('where')
->with([
'Tags.name' => 'foo',
'Tags.id !=' => 3
])
$query->expects($this->at(0))->method('where')
->with(['Tags.name' => 'foo'])
->will($this->returnValue($query));
$query->expects($this->at(1))->method('where')
->with(['Tags.id !=' => 3])
->will($this->returnValue($query));
$query->expects($this->once())->method('order')
@@ -510,7 +514,7 @@ public function testEagerLoaderFieldsException() {
->will($this->returnValue($query));
$query->expects($this->any())->method('contain')->will($this->returnSelf());
$query->expects($this->once())->method('where')->will($this->returnSelf());
$query->expects($this->exactly(2))->method('where')->will($this->returnSelf());
$association->eagerLoader([
'keys' => $keys,
@@ -560,10 +564,6 @@ public function testEagerLoaderSubquery() {
$query->expects($this->once())->method('execute')
->will($this->returnValue($results));
$query->expects($this->once())->method('where')
->with(['Tags.name' => 'foo'])
->will($this->returnSelf());
$expected = clone $parent;
$joins = $expected->join();
unset($joins[1]);
@@ -572,10 +572,14 @@ public function testEagerLoaderSubquery() {
->select('ArticlesTags.article_id', true)
->join($joins, [], true);
$query->expects($this->once())->method('where')
$query->expects($this->at(0))->method('where')
->with(['Tags.name' => 'foo'])
->will($this->returnValue($query));
$query->expects($this->at(1))->method('where')
->with([])
->will($this->returnValue($query));
$query->expects($this->once())->method('contain')
->with([
'ArticlesTags' => [
@@ -175,10 +175,14 @@ public function testEagerLoaderWithDefaults() {
$query->expects($this->once())->method('execute')
->will($this->returnValue($results));
$query->expects($this->once())->method('where')
$query->expects($this->at(0))->method('where')
->with(['Articles.is_active' => true])
->will($this->returnValue($query));
$query->expects($this->at(1))->method('where')
->with([])
->will($this->returnValue($query));
$query->expects($this->once())->method('andWhere')
->with(['Articles.author_id IN' => $keys])
->will($this->returnValue($query));
@@ -220,8 +224,12 @@ public function testEagerLoaderWithOverrides() {
$query->expects($this->once())->method('execute')
->will($this->returnValue($results));
$query->expects($this->once())->method('where')
->with(['Articles.is_active' => true, 'Articles.id !=' => 3])
$query->expects($this->at(0))->method('where')
->with(['Articles.is_active' => true])
->will($this->returnValue($query));
$query->expects($this->at(1))->method('where')
->with(['Articles.id !=' => 3])
->will($this->returnValue($query));
$query->expects($this->once())->method('andWhere')
@@ -316,7 +324,10 @@ public function testEagerLoaderSubquery() {
$query->expects($this->once())->method('execute')
->will($this->returnValue($results));
$query->expects($this->once())->method('where')
$query->expects($this->at(0))->method('where')
->with([])
->will($this->returnValue($query));
$query->expects($this->at(1))->method('where')
->with([])
->will($this->returnValue($query));

0 comments on commit 3acadff

Please sign in to comment.