Skip to content

Instantly share code, notes, and snippets.

@dakota
Created September 29, 2015 11:50
Show Gist options
  • Save dakota/1a12e6814ed3c816021d to your computer and use it in GitHub Desktop.
Save dakota/1a12e6814ed3c816021d to your computer and use it in GitHub Desktop.
<?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