Re: DataObjects: joinAdd problem
| From: | toni | Date: | Tue, 25 Jan 2005 13:11:51 +0000 |
| Subject: | Re: DataObjects: joinAdd problem | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-17146@lists.php.net to get a copy of this message | ||
Hi,
First, thank you for your responses. But, Justin, can you give me more
details of your propossed solutions?
I'm a bit confused, because I call a method of "Noticia" class but I
need the information of the "Not_Tema" class.
Can you explain where to put the whereAdd call and how to do the
comparison between id's , please?
Thank's all.
Toni.
El dl 24 de 01 del 2005 a les 09:52 -0800, en/na Justin Patrin va
escriure:
> On Mon, 24 Jan 2005 13:01:17 +0100, Toni <toni@pangea.org> wrote:
> > Hi,
> >
> > i'm coding a search page with DB_DO and I have a problem.
> >
> > My tables are:
> > Noticia: (id, titulo, ...); Tema: (id, ...); Not_Tema: (idn,idt);
> >
> > and my .links.ini:
> > [Not_Tema]
> > idn = Noticia:id
> > idt = Tema:id
> >
> > when I search from within Noticia class:
> >
> > $this->selectAdd('Noticia.id,titulo');
> > $this->orderBy('titulo');
> >
> > // search Noticias with a word within field "titulo":
> > if ($palabra!=''){
> > $this->whereAdd("(titulo LIKE
> > '%".$palabra."%')");
> > }
> >
> > // but only these ones that have a pair (idn,$v) in Not_Temas:
> > if (!empty($temas)) {
> > foreach ($temas as $v) {
> > $nt = new DataObjects_Not_Tema;
> > $nt->idt = $v;
>
> Instead of the above line, use whereAdd on $this and tell it to use OR
> instead of AND. Alternatively, you could just create the whole OR SQL
> yourself and whereAdd it after the loop. Or, my personal favorite,
> create an SQL list ('1', '2', '3') and use IN. "col IN
> ('1', '2',
> '3')" etc.
>
> > $this->joinAdd($nt,"");
> > }
> > }
> >
> > With only one value $v on pairs, this works, but how can I make that
> > works with more $v?
> >
> > This code generate ($v=3,$v=4): (DBDO error)
> > WHERE (titulo LIKE '%Salvador%')
> > AND Not_Not_Tema.idn=Not_Noticia.id AND Not_Not_Tema.idt = 3
> > AND Not_Not_Tema.idn=Not_Noticia.id AND Not_Not_Tema.idt = 4
> >
> > while I expect:
> > WHERE (titulo LIKE '%Salvador%')
> > AND (Not_Not_Tema.idn=Not_Noticia.id AND Not_Not_Tema.idt = 3
> > OR Not_Not_Tema.idn=Not_Noticia.id AND Not_Not_Tema.idt = 4)
> >
> > Can I do this with joinAdd?
> > If not, how can I do? Only with plain sql?
> >
> > Thanks in advance for your help.
> > Toni.
> >
>
> --
> Justin Patrin
>