Re: Complex Find Conditions (using arrays) , a bug in 1.2?

2007-11-21 Thread Adam Royle

I agree - it gets pretty convoluted when you add a bit of complexity
into the conditions.

However, I haven't yet come up with a better syntax (aside from
writing plain sql of course).

Have you got any suggestions?

Adam

On Nov 21, 3:23 am, zonium [EMAIL PROTECTED] wrote:
 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 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: Complex Find Conditions (using arrays) , a bug in 1.2?

2007-11-21 Thread AD7six

On Nov 21, 3:23 pm, Adam Royle [EMAIL PROTECTED] wrote:
 I agree - it gets pretty convoluted when you add a bit of complexity
 into the conditions.

Where is the complexity in the stated example?

Any nested array that is written on a single line is going to be
'difficult' to read as such it's easier to read if it's written as:

$conditions['OR']['PromoCode.start_date'] =  $datetime;
$conditions['OR']['PromoCode.promo_code'] = $promo_code;
$conditions['NOT']['PromoCode.active'] = 1; // or
$condiions['PromoCode.active'] = ' ' . 1;
$count =$this-PromoCode-findCount($conditions);

OR as:

$conditions = array(
 'OR' = array(
'PromoCode.start_date' =   $datetime,
'PromoCode.promo_code' =  $promo_code
  )
  'NOT' = array('PromoCode.active' = 1) // or 'PromoCode.active' =
' ' . 1
);
$count =$this-PromoCode-findCount($conditions);

Both of which are unambiguos (, identical) and easy to read. If you /
do/ write a more complex constraint you'll find it's quite easy to do
so if you adopt on or the other means of writing them.

my 2c, hth,

AD
--~--~-~--~~~---~--~~
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: Complex Find Conditions (using arrays) , a bug in 1.2?

2007-11-20 Thread zonium

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 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: Complex Find Conditions (using arrays) , a bug in 1.2?

2007-11-20 Thread zonium

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 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
-~--~~~~--~~--~--~---



Complex Find Conditions (using arrays) , a bug in 1.2?

2007-11-19 Thread zonium

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 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: Complex Find Conditions (using arrays) , a bug in 1.2?

2007-11-19 Thread Grant Cox

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 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
-~--~~~~--~~--~--~---