Is it possible to use UNION with CDbCriteria?
I can’t use findBySql because it is impossible paginate the result with CPagination in this case.
Is it possible to use UNION with CDbCriteria?
I can’t use findBySql because it is impossible paginate the result with CPagination in this case.
Why shouldnt it be possible? The only thing you have to do is to apply the limit / order manually to your sql statement.
Something like
$sql = "SELECT ...";
$sql .= " LIMIT " . $pagination->currentPage*$pagination->pageSize. ", " $pagination->pageSize
Maybe it will help you: http://www.yiiframework.com/doc/api/CDbCriteria
Look at CDbCriteria properties. You can use it as you want.
group string how to group the query results.
having string the condition to be applied with GROUP-BY clause.
join string how to join with other tables.
mergeWith() Merges with another criteria.
Was it helpfull?
No, it isn’t. I tried this, it merges conditions in WHERE only not using UNION. I think Dave’s advice is single way to solve my problem…
I found a solution: I created a view in Mysql with query needed and use simple model to get data from it!
Hi Husky,
Could you please tell more about the solution you’ve found? I need to make such query with Union too. How do you use simple model to the virtual table?
Thanks.