Issue Bug Closed

#62421Using array of constrains with "logicalAnd" or "logicalOR" results in strange nested queries

Dennis Biedermann 10/23/14, 12:46 updated 06/06/18, 16:07

Description

If you collect a set of constrains within an array and try to combine those constraints with “logicalAnd” or “logicalOr”, the result is a strange nested query.

Example

$customerConstraints = array(
    $query->equals('companyNo', 1),
    $query->equals('customerNo', 4711),
    $query->equals('customerAddrNo', 3)
);
$constraints = $query->logicalAnd($customerConstraints);

This should create a sql statement like:

... companyNo = '1' AND customerNo = '4711' AND customerAddrNo = '3'

but instead the result is something like this:

... (company_no = '1' AND customer_no = '9330') AND customer_addr_no = '0'

And it even gets worse if you add more constrains or try to combine different constraint sets with another “logicalAnd” or logicalOr’s a live example

        (
            (
                (
                    (
                        (
                            last_name LIKE '%Bier%' OR middle_name LIKE '%Bier%'
                        ) OR
                        first_name LIKE '%Bier%'
                    )
                    OR
                    street LIKE '%Bier%'
                )
                OR zip LIKE '%Bier%'
            )
            OR
            city LIKE '%Bier%'
        ) AND
        (
            (
                (    
                    (
                        last_name LIKE '%Hund%' OR middle_name LIKE '%Hund%'
                    ) OR
                    first_name LIKE '%Hund%'
                )
                OR
                street LIKE '%Hund%'
            ) OR
            zip LIKE '%Hund%'
        ) OR
        city LIKE '%Hund%'
    )
)

This is the result of simple addition of two constraint array with “logicalOr”.

IMHO this is a crucial bug and should be fixed ASAP.

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.