Custom find methods

90 views
Skip to first unread message

Ceeram

unread,
Feb 22, 2012, 12:44:35 PM2/22/12
to cakeph...@googlegroups.com
Hey everyone,

I have looked a bit more into custom find methods.

The model constructor doesnt merge findMethods with those of Model when defining public $findMethods = array('custom' => true) in AppModel.

Also Pagination often returns incorrect count results, when paginating a custom find type.

I have addressed both issues here:

https://github.com/ceeram/cakephp/compare/2.1...2.1-findMethods

Id like to get your feedback on this.

Greetings Ceeram

mark_story

unread,
Feb 28, 2012, 6:22:50 PM2/28/12
to cakephp-core
Looks good to me. One concern I have is how we handle custom find
methods that add fields. We should make sure that modifying
query['fields'] doesn't cause the count operation to fail. Perhaps
adding a separate key to the query data to indicate its a count
operation?

-Mark

Ceeram

unread,
Feb 29, 2012, 2:35:31 PM2/29/12
to cakeph...@googlegroups.com
I worked some more on this. In many cases the count now returns correct results for the custom find.
Jose also pointed out that with the count queries joins and other query params are not always wanted if it is a count operation even though it might return a correct count.
I added $query['operation'] = 'count', so that the custom finder can distinguish the query to build, if wanted.

All changes are now squashed into a single commit: https://github.com/ceeram/cakephp/commit/7fd09cb53b2c7f191c46d7c11003c2556f0cfe55

Greetings Ceeram

Op woensdag 29 februari 2012 00:22:50 UTC+1 schreef mark_story het volgende:

José Lorenzo Rodríguez

unread,
Feb 29, 2012, 2:58:24 PM2/29/12
to cakeph...@googlegroups.com
Looks good to me, nice job! 

mark_story

unread,
Mar 1, 2012, 1:49:21 PM3/1/12
to cakephp-core
Looks great, the extra operation key will be really useful for people
with custom finders, and lets them do all the hard work. I don't know
if you want to merge it into 2.1 or wait until the 2.2 branch gets
created.

-Mark

On Feb 29, 2:35 pm, Ceeram <c33...@gmail.com> wrote:
> I worked some more on this. In many cases the count now returns correct
> results for the custom find.
> Jose also pointed out that with the count queries joins and other query
> params are not always wanted if it is a count operation even though it
> might return a correct count.
> I added $query['operation'] = 'count', so that the custom finder can
> distinguish the query to build, if wanted.
>
> All changes are now squashed into a single commit:https://github.com/ceeram/cakephp/commit/7fd09cb53b2c7f191c46d7c11003...

Ceeram

unread,
Mar 1, 2012, 2:08:46 PM3/1/12
to cakeph...@googlegroups.com
I think the merge of findMethods can go into 2.1
The paginate changes i think would fit better in 2.2. I consider this being a bug, as it has not ever worked as it should. Probably many users created their workarounds for it, so i think it would be better to have this in the early stages of 2.2 perhaps as we are now too close to stable for this to be merged and perhaps break applications which run fine on current 2.1 branch.

Op donderdag 1 maart 2012 19:49:21 UTC+1 schreef mark_story het volgende:
Reply all
Reply to author
Forward
0 new messages