cakephp/cakephp — pull request #4175 by chinpei215 (2014-08-05 23:56:37+00:00)
Title: Fix afterFind() called twice with belongsTo and hasOne relationships

Fixes #2268

I have pulled an all-nighter reading DboSrouce.php.
Now I know everything ;)

I think that it is not a complex thing.
Top-level hasOne/belongsTo associations are fetched at [L1106](https://github.com/cakephp/cakephp/blob/aa42b80a4d386913a0b83ec1b18f396851f24919/lib/Cake/Model/Datasource/DboSource.php#L1106) and filtered at [L1118](https://github.com/cakephp/cakephp/blob/aa42b80a4d386913a0b83ec1b18f396851f24919/lib/Cake/Model/Datasource/DboSource.php#L1118).
Deep hasOne/belongsTo associations are fetched at [L1332](https://github.com/cakephp/cakephp/blob/aa42b80a4d386913a0b83ec1b18f396851f24919/lib/Cake/Model/Datasource/DboSource.php#L1332) and filtred at [L1380](https://github.com/cakephp/cakephp/blob/aa42b80a4d386913a0b83ec1b18f396851f24919/lib/Cake/Model/Datasource/DboSource.php#L1380).
Logic is about simplicity.

However, if top-level hasOne/belongsTo associations have more deep associations,
they are not fetched doubly because of if check at [L1320-1324](https://github.com/cakephp/cakephp/blob/aa42b80a4d386913a0b83ec1b18f396851f24919/lib/Cake/Model/Datasource/DboSource.php#L1320-1324), but filterd doubly.
I have fixed this issue.

But an old enough bug may become a feature.
I am not sure it should be merged on to master.