Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Custom finder methods will receive the full array of extra options
passed to the query every time
  • Loading branch information
lorenzo committed Jan 1, 2014
1 parent 32ccc1c commit ef98286
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
4 changes: 3 additions & 1 deletion Cake/ORM/Table.php
Expand Up @@ -697,7 +697,7 @@ public function belongsToMany($associated, array $options = []) {
*/
public function find($type = 'all', $options = []) {
$query = $this->query();
$query->select()->applyOptions($options);
$query->select();
return $this->callFinder($type, $query, $options);
}

Expand Down Expand Up @@ -1369,6 +1369,8 @@ protected function _processDelete($entity, $options) {
* @throws \BadMethodCallException
*/
public function callFinder($type, Query $query, $options = []) {
$query->applyOptions($options);
$options = $query->getOptions();
$finder = 'find' . ucfirst($type);
if (method_exists($this, $finder)) {
return $this->{$finder}($query, $options);
Expand Down
18 changes: 9 additions & 9 deletions Cake/Test/TestCase/ORM/TableTest.php
Expand Up @@ -552,7 +552,7 @@ public function testDeleteAllFailure() {
public function testFindApplyOptions() {
$table = $this->getMock(
'Cake\ORM\Table',
['query'],
['query', 'findAll'],
[['table' => 'users', 'connection' => $this->connection]]
);
$query = $this->getMock('Cake\ORM\Query', [], [$this->connection, $table]);
Expand All @@ -564,9 +564,15 @@ public function testFindApplyOptions() {
$query->expects($this->any())
->method('select')
->will($this->returnSelf());

$query->expects($this->once())->method('getOptions')
->will($this->returnValue(['connections' => ['a >' => 1]]));
$query->expects($this->once())
->method('applyOptions')
->with($options);

$table->expects($this->once())->method('findAll')
->with($query, ['connections' => ['a >' => 1]]);
$table->find('all', $options);
}

Expand Down Expand Up @@ -3012,7 +3018,7 @@ public function testGet() {

$query = $this->getMock(
'\Cake\ORM\Query',
['addDefaultTypes', 'first', 'applyOptions', 'where'],
['addDefaultTypes', 'first', 'where'],
[$this->connection, $table]
);

Expand All @@ -3023,9 +3029,6 @@ public function testGet() {
->with('all', $query, ['fields' => ['id']])
->will($this->returnValue($query));

$query->expects($this->once())->method('applyOptions')
->with(['fields' => ['id']])
->will($this->returnSelf());
$query->expects($this->once())->method('where')
->with(['bar' => 10])
->will($this->returnSelf());
Expand Down Expand Up @@ -3059,7 +3062,7 @@ public function testGetException() {

$query = $this->getMock(
'\Cake\ORM\Query',
['addDefaultTypes', 'first', 'applyOptions', 'where'],
['addDefaultTypes', 'first', 'where'],
[$this->connection, $table]
);

Expand All @@ -3069,9 +3072,6 @@ public function testGetException() {
->with('all', $query, ['contain' => ['foo']])
->will($this->returnValue($query));

$query->expects($this->once())->method('applyOptions')
->with(['contain' => ['foo']])
->will($this->returnSelf());
$query->expects($this->once())->method('where')
->with(['bar' => 10])
->will($this->returnSelf());
Expand Down

0 comments on commit ef98286

Please sign in to comment.