Monday, February 25, 2013

Re: Inner Join cakephp

I have updated the qeustion:

I have these 2 tables: cd_biblio (which contains a list of books) and cd_bibliotem (which contains only the id of book and id of tag).
I want to make a query where the user can choose also the tag of a book (in both tables the tags are numeric).
In the cd_biblios controller I add:

App::import('Model', 'CdBibliotem');  $CdBibliotem = new CdBibliotem();

I made the queries for cd_biblio table in this way:

// General query  $conditions = array(      'editore LIKE' => "%$e%",      'titolo LIKE' => "%$t%"  );

And then for example: 

if (!$anno)          $conditions[] = array('anno <=' => "$anno2");            if (!$anno2)          $conditions[] = array('anno >=' => "$anno");

Or: 

if (isset($menu)&&$menu!='')          $conditions[]=array('classe LIKE' => "%$menu%");

Now I need to do a inner join between these 2 tables to get all the books with a specific tags. 
I save tags in string, so I use: 
SELECT ... WHERE tags IN ('$tags'); 
But I can't make a inner join using $conditions. 

I tried something like this: 

$t = $CdBibliotem->query("SELECT * FROM cd_bibliotem WHERE codiceTematica = '$tematiche'");       $t = Set::classicExtract($t,'{n}.cd_bibliotem.codiceBiblio');

Now I need to compare these books ids (codiceBiblio) with that from the first query (with an inner join), so I tried:

$tem = $CdBibliotem->find('all', array('joins' => array(               array(           'table' => 'cd_biblio',           'alias' => 'Tag',           'type' => 'inner',           'conditions'=> array('Tag.codiceBiblio' => $t)       )   ))); 

But it's not working, apache2 process start to take a lot of ram, and makes the PC unusable (I'm using cakephp ver 1.2)

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: