{"action":"opened","issue":{"url":"https://api.github.com/repos/cakephp/cakephp/issues/5689","labels_url":"https://api.github.com/repos/cakephp/cakephp/issues/5689/labels{/name}","comments_url":"https://api.github.com/repos/cakephp/cakephp/issues/5689/comments","events_url":"https://api.github.com/repos/cakephp/cakephp/issues/5689/events","html_url":"https://github.com/cakephp/cakephp/issues/5689","id":54684316,"number":5689,"title":"Query::formatResults() receives only a single argument of type \\Cake\\Collection\\Collection for hasOne/belongsTo","user":{"login":"ndm2","id":5031606,"avatar_url":"https://avatars.githubusercontent.com/u/5031606?v=3","gravatar_id":"","url":"https://api.github.com/users/ndm2","html_url":"https://github.com/ndm2","followers_url":"https://api.github.com/users/ndm2/followers","following_url":"https://api.github.com/users/ndm2/following{/other_user}","gists_url":"https://api.github.com/users/ndm2/gists{/gist_id}","starred_url":"https://api.github.com/users/ndm2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ndm2/subscriptions","organizations_url":"https://api.github.com/users/ndm2/orgs","repos_url":"https://api.github.com/users/ndm2/repos","events_url":"https://api.github.com/users/ndm2/events{/privacy}","received_events_url":"https://api.github.com/users/ndm2/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-01-18T02:58:58Z","updated_at":"2015-01-18T02:58:58Z","closed_at":null,"body":"I can't tell for sure whether this is a bug, but it's certainly unexpected jugding from the docs and the existing tests.\r\n\r\n```php\r\npublic function testFormatResultsForHasOneAssociation()\r\n{\r\n\t$table = TableRegistry::get('authors');\r\n\t$table->hasOne('articles');\r\n\r\n\t$articles = TableRegistry::get('articles');\r\n\r\n\t$articles->eventManager()->attach(function ($event, $query) {\r\n\t\t$query->formatResults(function ($results, $query) {\r\n\t\t\t$this->assertInstanceOf('\\Cake\\Datasource\\ResultSetInterface', $results);\r\n\t\t\t$this->assertInstanceOf('\\Cake\\Database\\Query', $query);\r\n\r\n\t\t\treturn $results->map(function ($entity) {\r\n\t\t\t\t$entity->foo = 'bar';\r\n\t\t\t\treturn $entity;\r\n\t\t\t});\r\n\t\t});\r\n\t}, 'Model.beforeFind');\r\n\r\n\t$result = $table->get(1, ['contain' => ['articles']]);\r\n\r\n\t$this->assertEquals('bar', $result->article->foo);\r\n}\r\n\r\npublic function testFormatResultsForBelongsToAssociation()\r\n{\r\n\t$table = TableRegistry::get('articles');\r\n\t$table->belongsTo('authors');\r\n\r\n\t$authors = TableRegistry::get('authors');\r\n\r\n\t$authors->eventManager()->attach(function ($event, \\Cake\\ORM\\Query $query) {\r\n\t\t$query->formatResults(function ($results, $query) {\r\n\t\t\t$this->assertInstanceOf('\\Cake\\Datasource\\ResultSetInterface', $results);\r\n\t\t\t$this->assertInstanceOf('\\Cake\\Database\\Query', $query);\r\n\r\n\t\t\treturn $results->map(function ($entity) {\r\n\t\t\t\t$entity->foo = 'bar';\r\n\t\t\t\treturn $entity;\r\n\t\t\t});\r\n\t\t});\r\n\t}, 'Model.beforeFind');\r\n\r\n\t$result = $table->get(1, ['contain' => ['authors']]);\r\n\r\n\t$this->assertEquals('bar', $result->authors->foo);\r\n}\r\n\r\npublic function testFormatResultsForHasManyAssociation()\r\n{\r\n\t$table = TableRegistry::get('authors');\r\n\t$table->hasMany('articles');\r\n\r\n\t$articles = TableRegistry::get('articles');\r\n\r\n\t$articles->eventManager()->attach(function ($event, $query) {\r\n\t\t$query->formatResults(function ($results, $query) {\r\n\t\t\t$this->assertInstanceOf('\\Cake\\Datasource\\ResultSetInterface', $results);\r\n\t\t\t$this->assertInstanceOf('\\Cake\\Database\\Query', $query);\r\n\r\n\t\t\treturn $results->map(function ($entity) {\r\n\t\t\t\t$entity->foo = 'bar';\r\n\t\t\t\treturn $entity;\r\n\t\t\t});\r\n\t\t});\r\n\t}, 'Model.beforeFind');\r\n\r\n\t$result = $table->get(1, ['contain' => ['articles']]);\r\n\r\n\t$this->assertEquals('bar', $result->articles[0]->foo);\r\n}\r\n\r\npublic function testFormatResultsForBelongsToManyAssociation()\r\n{\r\n\t$table = TableRegistry::get('articles');\r\n\t$table->belongsToMany('tags');\r\n\r\n\t$tags = TableRegistry::get('tags');\r\n\r\n\t$tags->eventManager()->attach(function ($event, $query) {\r\n\t\t$query->formatResults(function ($results, $query) {\r\n\t\t\t$this->assertInstanceOf('\\Cake\\Datasource\\ResultSetInterface', $results);\r\n\t\t\t$this->assertInstanceOf('\\Cake\\Database\\Query', $query);\r\n\r\n\t\t\treturn $results->map(function ($entity) {\r\n\t\t\t\t$entity->foo = 'bar';\r\n\t\t\t\treturn $entity;\r\n\t\t\t});\r\n\t\t});\r\n\t}, 'Model.beforeFind');\r\n\r\n\t$result = $table->get(1, ['contain' => ['tags']]);\r\n\r\n\t$this->assertEquals('bar', $result->tags[0]->foo);\r\n}\r\n```\r\n\r\nYou should see that the `testFormatResultsForHasOneAssociation` and `testFormatResultsForBelongsToAssociation` tests do fail as they only receive a single argument, which is of type `\\Cake\\Collection\\Collection`."}}