On Dec 5, 2006, at 2:40 PM, Ruslan Zakirov wrote:

On 12/5/06, Jesse Vincent <[EMAIL PROTECTED]> wrote:



On Tue, Dec 05, 2006 at 04:01:04PM +0800, Agent Zhang wrote:
> Hi,
>
> The Jifty::Manual::Models document contains the following snippet:
>
>    # combining restrictions with "AND"
>    # note that "AND" is implicit here
>    $collection->limit(column=>'col1', value=>'...');
>    $collection->limit(column=>'col2', value=>'...');
>
> While testing my Qooqle app in Jifty, however, I found "OR" is
> implicit here instead. By further examining the source of
> Jifty::DBI::Collection, I've seen the following lines:


Here's the way it works:


* Toplevel clauses default to AND
* Subclauses default to OR (though at one point, they defaulted to
whatever made sense. You can make decent guesses about what the user
  means...except that you're often wrong);
* By default, each column gets its own subclauses.

So:


$collection->limit(column =>  'col1', value => 'x');
$collection->limit(column =>  'col1', value => 'y');

        Will generate :

        WHERE ( col1 = 'x' OR col2 = 'y');
         WHERE ( col1 = 'x' AND col2 = 'y');

How so? My reading of sub limit says this:


sub limit {
    my $self = shift;
    my %args = (

        ...
        entry_aggregator => 'or',
        ...

         @_    # get the real argumentlist
    );






$collection->limit(column =>  'col1', value => 'x');
$collection->limit(column =>  'col2', value => 'y');

        Will generate:

        WHERE ( col1 = 'x' ) AND  ( col2 = 'y');

$collection->limit(column =>  'col1', value => 'x');
$collection->limit(column =>  'col2', value => 'x');
$collection->limit(column =>  'col2', value => 'y');

        Will generate:

        WHERE ( col1 = 'x' ) AND  ( col2 = 'x' OR col2 = 'y');



You can get tricky by playing with the entry aggregator yourself:

$collection->limit(column =>  'col1', value => 'x');
$collection->limit(column => 'col2', value => 'x', entry_aggregator => 'AND'); $collection->limit(column => 'col2', value => 'y', entry_aggregator => 'AND');

        Will generate:

        WHERE ( col1 = 'x' ) AND  ( col2 = 'x' OR col2 = 'y');
         WHERE ( col1 = 'x' ) AND  ( col2 = 'x' AND col2 = 'y');


Thanks. Nice catch.

_______________________________________________
jifty-devel mailing list
[email protected]
http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-devel

Reply via email to