Created
September 29, 2015 11:50
-
-
Save dakota/1a12e6814ed3c816021d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Tests that belongsTo contains can be called on an unbuffered query | |
* | |
* @return void | |
*/ | |
public function testContainUnbuffered() | |
{ | |
$table = TableRegistry::get('Articles'); | |
$table->belongsTo('Authors'); | |
$table->Authors->eventManager() | |
->on('Model.beforeFind', function (Event $event, Query $query) { | |
$query->formatResults(function ($results) { | |
return $results; | |
}); | |
}); | |
$query = new Query($this->connection, $table); | |
$query | |
->bufferResults(false) | |
->contain(['Authors']) | |
->where([ | |
'Authors.id' => 1 | |
]); | |
foreach ($query as $item) { | |
$this->assertArrayHasKey('id', $item); | |
$this->assertArrayHasKey('author', $item); | |
$this->assertArrayHasKey('name', $item['author']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment