?

Log in

cakephp

Need your help

« previous entry |
Sep. 17th, 2010 | 07:41 pm
posted by: may_cat_ghost in cakephp

 Hi there.

My model uses multiply tables, not single one. Those tables have unique CHAR strings as primary key, so their contents don't intersect.

I need my model to search through all of these tables. But cake's FIND method doesn't allow to specify table to search in. And also doesn't allow to use mysql's UNITE constructions.
So, I should use such an monster construction like

__________________________________________
$this->setSource($table1);
$r=$this->find(....);
if (! $r)
{
$this->setSource($table2);
$r=$this->find(....);
}
if (! $r)
{
$this->setSource($table3);
$r=$this->find(....);
}
& etc
__________________________________________

It seems to me to be at least extreamly slow. All this job can be mady with only one MySQL query like:

__________________________________________
SELECT <..> FROM `<table1>` WHERE <..> ORDER <..> <...>
UNITE
SELECT <..> FROM `<table2>` WHERE <..> ORDER <..> <...>
UNITE
SELECT <..> FROM `<table3>` WHERE <..> ORDER <..> <...>
& etc
__________________________________________

Do you have idea, how to do it? It seems to me, that the only way is copypasting cake's "find" method and changing it my situation.
Maybee there is another way?

Update
Solution found.

Link | Leave a comment | Share

Comments {0}