Re: paginateCount and SELECT DISTINCT

2009-03-17 Thread Fibra

Anyone?

On Mar 16, 3:15 pm, Fibra  wrote:
> Hello everyone, how are you?
>
> If you ever had the misfortune of finding yourself in the need of
> using the $paginate variable with a DISTINCT operation, you must have
> found out that the returned amount of records is not correct! It
> returns the COUNT of all the records (ignoring the DISTINCT in the
> fields array) instead of the COUNT(DISTINCT id), for example.
>
> I've been looking all over the web for a solution to this particular
> case of pagination but they all involved rewriting the paginateCount
> method for a particular case of pagination, which is not what I want
> (I want cake to keep doing all the magic for me :D ). So, I've been
> playing with the cake lib, and found a way to solve it, however... I
> assume it might have side effects, and would like your opinion on the
> matter, whether this can be implemented in a "cleaner" way or if I'm
> totally off track.
>
> So, in the controller.php find method, I've placed (REplaced,
> actually) this code (Line 1030):
>
>                 if (method_exists($object, 'paginateCount')) {
>                         $count = $object->paginateCount($conditions, 
> $recursive, $extra);
>                 } else {
>                         $parameters = compact('conditions');
>                         if ($recursive != $object->recursive) {
>                                 $parameters['recursive'] = $recursive;
>                         }
>                         //$count = $object->find('count', 
> array_merge($parameters,
> $extra)); //OLD LINE
>                         $count = $object->find('count', $fields); //NEW LINE
>                 }
>
> In my controller, the code for the paginate variable is as follows:
>
>                 var $paginate = array(
>                         'limit' => 25,
>                         'order' => array(
>                                 'User.created' => 'desc'
>                         ),
>                         'joins' => array(
>                                 'LEFT JOIN user_areas AS Areas ON User.id = 
> Areas.user_id',
>                                 'LEFT JOIN user_tools AS Tools ON User.id = 
> Tools.user_id',
>                                 'LEFT JOIN user_careers AS Careers ON User.id 
> = Careers.user_id'
>                         ),
>                         'fields' => array(
>                                 'DISTINCT User.id',
>                                 'User.dni',
>                                 'User.name',
>                                 'User.email',
>                                 'User.password',
>                                 'User.interviewed',
>                                 'User.keywords',
>                                 'User.birthday',
>                                 'User.cv',
>                                 'User.filetype',
>                                 'User.comment',
>                                 'User.province_id',
>                                 'User.town',
>                                 'User.remuneration',
>                                 'User.created',
>                                 'User.modified',
>                                 'User.admin',
>                                 'Province.id',
>                                 'Province.country_id',
>                                 'Province.name',
>                                 'UserSecondary.id',
>                                 'UserSecondary.user_id',
>                                 'UserSecondary.secondary_id',
>                                 'UserSecondary.institute',
>                                 'UserSecondary.status_id'
>                         )
>                 );
>
> So, I would like to hear some thoughts please.
>
> Thanks in advance!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



paginateCount and SELECT DISTINCT

2009-03-16 Thread Fibra

Hello everyone, how are you?

If you ever had the misfortune of finding yourself in the need of
using the $paginate variable with a DISTINCT operation, you must have
found out that the returned amount of records is not correct! It
returns the COUNT of all the records (ignoring the DISTINCT in the
fields array) instead of the COUNT(DISTINCT id), for example.

I've been looking all over the web for a solution to this particular
case of pagination but they all involved rewriting the paginateCount
method for a particular case of pagination, which is not what I want
(I want cake to keep doing all the magic for me :D ). So, I've been
playing with the cake lib, and found a way to solve it, however... I
assume it might have side effects, and would like your opinion on the
matter, whether this can be implemented in a "cleaner" way or if I'm
totally off track.

So, in the controller.php find method, I've placed (REplaced,
actually) this code (Line 1030):

if (method_exists($object, 'paginateCount')) {
$count = $object->paginateCount($conditions, 
$recursive, $extra);
} else {
$parameters = compact('conditions');
if ($recursive != $object->recursive) {
$parameters['recursive'] = $recursive;
}
//$count = $object->find('count', 
array_merge($parameters,
$extra)); //OLD LINE
$count = $object->find('count', $fields); //NEW LINE
}

In my controller, the code for the paginate variable is as follows:

var $paginate = array(
'limit' => 25,
'order' => array(
'User.created' => 'desc'
),
'joins' => array(
'LEFT JOIN user_areas AS Areas ON User.id = 
Areas.user_id',
'LEFT JOIN user_tools AS Tools ON User.id = 
Tools.user_id',
'LEFT JOIN user_careers AS Careers ON User.id = 
Careers.user_id'
),
'fields' => array(
'DISTINCT User.id',
'User.dni',
'User.name',
'User.email',
'User.password',
'User.interviewed',
'User.keywords',
'User.birthday',
'User.cv',
'User.filetype',
'User.comment',
'User.province_id',
'User.town',
'User.remuneration',
'User.created',
'User.modified',
'User.admin',
'Province.id',
'Province.country_id',
'Province.name',
'UserSecondary.id',
'UserSecondary.user_id',
'UserSecondary.secondary_id',
'UserSecondary.institute',
'UserSecondary.status_id'
)
);

So, I would like to hear some thoughts please.

Thanks in advance!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



AppController being ignored

2008-10-09 Thread Fibra

Hello Everyone, how are you?

I've read this issue in other posts but most of the solutions are
becouse they've updated to a newer version.

Since I just downloaded the latest stable version on cake,
cake_1.2.0.7692-rc3.tar.bz2 I must ask for help.

Here's the thing:

I have my routing.admin turned on, and placed my app_controller.php
under /app

here's the code:

params['admin'])) {
$this->layout = 'admin';
}
}

}
?>

Neither 'ok' or 'wtf' get printed once I access /admin/events, however
they DO get printed when I access /admin, but that's becouse I forced
to have the admin_layout like this:

Router::connect('/admin', array('controller' => 'pages','layout' =>
'admin', 'action' => 'display', 'admin_home'));

So, any ideas? Do I have to post more info for this issue?

Thanks in advance!

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---