On Dec 13, 12:20 am, Mr-Yellow <[EMAIL PROTECTED]> wrote:
> Was this typed right?
>
> array(
>         'Foo.Cat' => 'LIKE a%',
>         array(
>                 'Foo.Cat' => 'LIKE b%'
>         ),
>         array(
>                 'Foo.Cat' => 'LIKE c%'
>         )
> );
>
> They have to be nested like that or did you mean.....
>
> array(
>         array(
>                 'Foo.Cat' => 'LIKE a%'
>         ),
>         array(
>                 'Foo.Cat' => 'LIKE b%'
>         ),
>         array(
>                 'Foo.Cat' => 'LIKE c%'
>         ),
> )
>
> ?
>
> -Ben

Either.

A nested array simply adds brackets to the sql, so has no functional
impact - but prevents you overwriting array keys in php (as you
pointed out). You can nest them as much or as little as you want/need.

I wouldn't agree that array constraints are not intuitive, the problem
comes ofter (IMO) from considering sql as a sentance and trying to
write a flat array to match.

Some basics to bear in mind:

1) whatever the 'type' of array (AND, OR, NOT, OR NOT) is what is used
to implode each array element
2) AND is the default array type
3) ORs need more than 1 array element otherwise, or what?
4) theres more than one way to prevent overwriting an array key, as
theres more than 1 way to write any constraint.

e.g. consider, find all unpublished posts by me, you or bob. only bobs
post from last week.

this makes no sense, even if you correct the overwritten keys:
array(
  'Post.owner' => 'me',
  'OR' => 'Post.owner' => 'you',
  'OR' => 'Post.owner' => 'bob',
  'AND' => 'Post.created' => '< ' . lastweek,
  'NOT' => 'Post.published' => true
)

The problem is that the sql statement would need brackets to be
defined unambiguously and sql brackets = an array.

array(
   'OR' => array(
      'Post.owner' => 'me',
      array('Post.owner' => 'you'),
      array(
        'Post.owner' => 'bob',
        'Post.created' => '> ' . lastweek
      )
  ),
  'NOT' => 'Post.published' => true
)

Is unambiguous as a php array, and the sql would be also.

Anyway, 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