datasources icon indicating copy to clipboard operation
datasources copied to clipboard

Patches ArrayDatasource by disabling fields-filtering, fixing broken results on hasMany/HABTM scenarios

Open albertboada opened this issue 11 years ago • 0 comments

Patches Array Datasource by disabling fields-filtering feature, since it was not behaving properly when querying hasMany/HABTM related models (see commit's source code for detailed explanation).

The reason for this patch lies on a strange behaviour in CakePHP 1.3.X's DBO Datasource (https://github.com/cakephp/cakephp/blob/1.3/cake/libs/model/datasources/dbo_source.php#L1230), where $queryData['fields'] is polluted with a fields list from the root model when querying its hasMany/HABTM relationships, thus affecting all the following queries on related models (since $queryData is passed by reference). This pollution affected the following bit of code in a way that, if no fields for the current relationship were initially specified by the developer when executing a find(), it would unset ALL of them, giving almost blank results. Since trying to fully understand all the side effects that changing CakePHP's DBO Datasource would carry, and since field-filtering makes almost no sense in terms of optimization on Array Datasources (unlike in SQL), this patch consists in voiding field-filtering on Array Datasource's models.

Any experience on this scenario, anyone?

albertboada avatar Oct 08 '14 11:10 albertboada