I figured it out:
The statement should be:
$count =$this->PromoCode-
>findCount(array('or'=>array(array("PromoCode.start_date" =>">
$datetime", 'PromoCode.promo_code'=>$promo_code),
array('PromoCode.active'=>'<>1'))));

and the result is as expected:
SELECT COUNT(*) AS `count` FROM `promo_codes` AS `PromoCode` WHERE
(((`PromoCode`.`start_date` > '2007-11-20 09:11:23') AND
(`PromoCode`.`promo_code` = 'freemug')) OR (`PromoCode`.`active` <>
1))

But ... Too complicated a statement for a simple query. Don't you
think?
Thanks!

On Nov 20, 8:55 am, zonium <[EMAIL PROTECTED]> wrote:
> In fact, my select statement was
>
> $count =$this->PromoCode->findCount(array("PromoCode.start_date" =>">
> $datetime", 'PromoCode.promo_code'=>$promo_code,
> "OR"=>array('PromoCode.active'=>'<>1')));
> and
>
> Cake created:
> SELECT COUNT(*) AS `count` FROM `promo_codes` AS `PromoCode` WHERE
> `PromoCode`.`start_date` > '2007-11-19 08:50:20' AND
> `PromoCode`.`promo_code` = 'freemug' AND ((`PromoCode`.`active` <> 1))
>
> I expected
>
> SELECT COUNT(*) AS `count` FROM `promo_codes` AS `PromoCode` WHERE
> (`PromoCode`.`start_date` > '2007-11-19 08:50:20' AND
> `PromoCode`.`promo_code` = 'freemug') OR ((`PromoCode`.`active` <> 1))
>
> Thanks,
>
> On Nov 19, 8:42 pm, Grant Cox <[EMAIL PROTECTED]> wrote:
>
> > Put both conditions in the 'or' key:
>
> > $datetime =  date("Y-m-d H:i:s");
> > $count 
> > =$this->PromoCode->findCount(array("OR"=>array("PromoCode.start_date" =>"> 
> > $datetime",
>
> > 'PromoCode.active'=>'<>1')));
>
> > On Nov 20, 11:49 am, zonium <[EMAIL PROTECTED]> wrote:
>
> > > I have these statements:
>
> > > $datetime =  date("Y-m-d H:i:s");
> > > $count =$this->PromoCode->findCount(array("PromoCode.start_date" =>">
> > > $datetime", "OR"=>array('PromoCode.active'=>'<>1')));
>
> > > With debug enabled I saw cake tried to create this query:
>
> > > SELECT COUNT(*) AS `count` FROM `promo_codes` AS `PromoCode` WHERE
> > > `PromoCode`.`start_date` > '2007-11-19 17:38:54' AND
> > > ((`PromoCode`.`active` <> 1))
>
> > > According to the official manual (http://manual.cakephp.org/chapter/
> > > models) I expected
>
> > > OR (`PromoCode`.`active` <> 1)
> > > instead of
> > > AND ((`PromoCode`.`active` <> 1))
>
> > > Is it a bug or my statement was not correctly written.
>
> > > Thanks,

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to