RE: findAll query problem - mutiple conditions for one field not executing

2006-12-14 Thread Mariano Iglesias

Did he send a ticket? I thought we covered this with my previous response.

-MI

---

Remember, smart coders answer ten questions for every question they ask. 
So be smart, be cool, and share your knowledge. 

BAKE ON!


-Mensaje original-
De: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] En nombre
de nate
Enviado el: Jueves, 14 de Diciembre de 2006 10:34 p.m.
Para: Cake PHP
Asunto: Re: findAll query problem - mutiple conditions for one field not
executing

It gets overwritten because you're not allowed to have two array
elements with the same key, it's impossible.  See my response to your
ticket: https://trac.cakephp.org/ticket/1766


--~--~-~--~~~---~--~~
 You received this message because you are subscribed to the Google Groups 
"Cake PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: findAll query problem - mutiple conditions for one field not executing

2006-12-14 Thread nate

It gets overwritten because you're not allowed to have two array
elements with the same key, it's impossible.  See my response to your
ticket: https://trac.cakephp.org/ticket/1766


--~--~-~--~~~---~--~~
 You received this message because you are subscribed to the Google Groups 
"Cake PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: findAll query problem - mutiple conditions for one field not executing

2006-12-14 Thread gabordemeter

Ok, I have found the problem and a fix:

The problem is that the first Abc.focus condition gets overwritten by
the second one in the $conditions array like Mariano suggested above.
The simplest solution looks like below:

function aaa($focus_low, $focus_high)
{
$items = $this->Abc->findAll(array(
'Abc.users_id' => $this->Session->read('User.id'),
'Abc.focus >= '.$focus_low.' AND Abc.focus <= '.$focus_high
), null, 'startdate ASC');
}




On Dec 14, 8:46 am, "gabordemeter" <[EMAIL PROTECTED]> wrote:
> I have a problem with a findAll() query. The code is:
>
> $items = $this->Abc->findAll(array(
> 'Abc.users_id' => $this->Session->read('User.id'),
> 'Abc.focus' => ">= 3",
> 'Abc.focus' => "<= 3"
> ), null, 'startdate ASC');
>
> What I want is to find those items which have focus = 3. But the code
> above finds items which have focus <= 3.
>
> You may wonder why I don't not just use: 'Abc.focus' => "3"?
>
> Because this is part of a function:
>
> function aaa($focus_low, $focus_high)
> {
> $items = $this->Abc->findAll(array(
> 'Abc.users_id' => $this->Session->read('User.id'),
> 'Abc.focus' => ">= ".$focus_low,
> 'Abc.focus' => "<= ".$focus_high
> ), null, 'startdate ASC');
>
> }So in some cases when I call this function i may want to find items
> higher than or equal to 1 AND lower than or equal to 3. But in other
> cases, like the above, i just want items which are equal to 3.
> 
> Thanks!


--~--~-~--~~~---~--~~
 You received this message because you are subscribed to the Google Groups 
"Cake PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



RE: findAll query problem - mutiple conditions for one field not executing

2006-12-14 Thread Mariano Iglesias

First of all the way you are defining the conditions make use of an indexed
array, so beware of overwriting the same index. Why don't you just break it
down like:

function aaa($focus_low, $focus_high)
{
$conditions = array (
'Abc.users_id' => $this->Session->read('User.id'),
);

if ($focus_low == $focus_height)
{
$conditions['Abc.focus'] = $focus_low;
}
else
{
$conditions[] = array ('Abc.focus' => ">= ".$focus_low);
$conditions[] = array ('Abc.focus' => "<= ".$focus_high);
}

$items = $this->Abc->findAll($conditions, null, 'startdate ASC');

return $items;
}

Try that, I haven't tested it. If it doesn't work (that is, the expression
after previous else) try:

else
{
$conditions = 'Abc.users_id = ' . $this->Session->read('User.id');
$conditions .= ' AND ';
$conditions .= 'Abc.focus >= ' . $focus_low;
$conditions .= ' AND ';
$conditions .= 'Abc.focus <= ' . $focus_high;
}

-MI

---

Remember, smart coders answer ten questions for every question they ask. 
So be smart, be cool, and share your knowledge. 

BAKE ON!


-Mensaje original-
De: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] En nombre
de gabordemeter
Enviado el: Jueves, 14 de Diciembre de 2006 10:47 a.m.
Para: Cake PHP
Asunto: findAll query problem - mutiple conditions for one field not
executing

So in some cases when I call this function i may want to find items
higher than or equal to 1 AND lower than or equal to 3. But in other
cases, like the above, i just want items which are equal to 3.


--~--~-~--~~~---~--~~
 You received this message because you are subscribed to the Google Groups 
"Cake PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---