Skip to content

Commit

Permalink
Adding test for leftJoinWith() and select()
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jun 4, 2015
1 parent abd4cd3 commit 0949911
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/TestCase/ORM/QueryTest.php
Expand Up @@ -2739,4 +2739,33 @@ public function testLeftJoinWithNested()
$fields = ['total_articles', 'id', 'name'];
$this->assertEquals($fields, array_keys($results->first()->toArray()));
}

/**
* Tests that leftJoinWith() can be used with select()
*
* @return void
*/
public function testLeftJoinWithSelect()
{
$table = TableRegistry::get('authors');
$articles = $table->hasMany('articles');
$articles->belongsToMany('tags');
$results = $table
->find()
->leftJoinWith('articles.tags', function ($q) {
return $q
->select(['articles.id', 'articles.title'])
->where(['tags.name' => 'tag3']);
})
->autoFields(true)
->group(['authors.id'])
->all();

$expected = ['id' => 3, 'title' => 'Third Article'];
$this->assertEquals(
$expected,
$results->first()->_matchingData['articles']->toArray()
);
$this->assertNull($results->last()->_matchingData['articles']->id);
}
}

0 comments on commit 0949911

Please sign in to comment.