On Feb 18, 10:52 am, orbdex <[EMAIL PROTECTED]> wrote:
> Hey there,
>
> I've read a lot about the complex find methods in the cake
> documentation but there is one thing i do not get to work properly:
>
> image i would like to have a resulting sql like
>
> select a.* from startpage a left join contents b on a.content_id=b.id
> where (b.online_from = '0000-00-00' and b.online_to = '0000-00-00') OR
> ('b.online_from <= '2008-01-01' and b.online_to >= '2008-12-31')
>
> I tried to build my $conditions array like the following:
>
>                 $conditions = array(
>                         'or' => array(
>                                 'and' => array(
>                                         'StartPage.online_from' => 
> '0000-00-00',
>                                         'StartPage.online_to' => '0000-00-00',
>                                 ),
>                                 'and' => array(
>                                         'StartPage.online_from' => 
> '<=2008-02-01',
>                                         'StartPage.online_to' => 
> '>=2008-02-29'
>                                 )
>                         )
>                 );
>
> Problem is: cake cuts the statement: The result i get is:
> SELECT `StartPage`.`id`, `StartPage`.`content_id`, `StartPage`.`sort`,
> `StartPage`.`online_from`, `StartPage`.`online_to`, `Content`.`id`,
> `Content`.`created`, `Content`.`title`, `Content`.`intro`,
> `Content`.`content`, `Content`.`image`, `Content`.`link`,
> `Content`.`targetable`, `Content`.`targetasset`, `Content`.`type`,
> `Content`.`user_id` FROM `startpage` AS `StartPage` LEFT JOIN
> `contents` AS `Content` ON (`StartPage`.`content_id` = `Content`.`id`)
> WHERE ((((`StartPage`.`online_from` <= '2008-02-01') AND
> (`StartPage`.`online_to` >= '2008-02-29')))) LIMIT 10
>
> Ideas? Maybe the solution is simple but I'm a bit puzzled...

You have $conditions['or']['and'] written once (which means once as
far as php is concerned)

Use:
               $conditions = array(
                        'OR' => array(
                                array(
                                        'StartPage.online_from' =>
'0000-00-00',
                                        'StartPage.online_to' =>
'0000-00-00',
                                ),
                                array(
                                        'StartPage.online_from' =>
'<=2008-02-01',
                                        'StartPage.online_to' =>
'>=2008-02-29'
                                )
                        )
                );

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