Hi guys, I am having a problem with active record. Here is my story:
I am trying to emulate this SQL query with an active record:
SQL query:
select emailaddr from address where id in (select linkitem from folderlink where folderid='2');
Active record query:
address::model()->findAll("id in (select linkitem from folderlink where folderid=:folderid)",array(":folderid"=>$_GET['id']));
Active record is doing it’s job and returning me what I need, but here is a problem I need to split the result into pages with CPagination.
Here is what I do (quite standard approach):
In my controller I am using this action:
public function actionShowitems()
{
$form = new AddFolderItemsForm;
$criteria=new CDbCriteria;
$pages=new CPagination(address::model()->count("id in (select linkitem from folderlink where folderid=:folderid)",array(":folderid"=>$_GET['id'])));
$pages->pageSize=self::PAGE_SIZE;
$pages->applyLimit($criteria);
$models=address::model()->findAll("id in (select linkitem from folderlink where folderid=:folderid)",array(":folderid"=>$_GET['id']));
$this->renderPartial('additems',array(
'models'=>$models,
'form'=>$form,
'pages'=>$pages
));
}
My problem is I need to know where to put criteria in address::model()->findAll , because if I am doing like this:
$models=address::model()->findAll("id in (select linkitem from folderlink where folderid=:folderid)",array(":folderid"=>$_GET['id']),$criteria);
It’s not working.
Any ideas, how can I do that?
Thanks.