Ticket #939 (closed defect: fixed)

Opened 8 months ago

Last modified 3 months ago

OR has precedence over AND

Reported by: frosas Owned by: romanb
Priority: major Milestone:
Component: Query/Hydration Version: 0.11.0
Keywords: Cc:
Has Test: Status:
Has Patch:

Description

It happens that in DQL the logical operator OR has precedence over AND, which it neither behaves according to common sense nor the manual.

I'll use the Doctrine_Query_Condition unit test code as example. The WHERE condition:

(User.name LIKE 'z%') OR User.name LIKE 's%' AND User.name LIKE 'a%'

is expected to become:

(e.name LIKE 'z%' OR (e.name LIKE 's%' AND e.name LIKE 'a%'))

(note the brackets are opcional) but this is what we get:

((e.name LIKE 'z%' OR e.name LIKE 's%') AND e.name LIKE 'a%')

Attached is the patch that hopefully solves this.

Attachments

patch.diff (1.7 KB) - added by frosas 8 months ago.

Change History

Changed 8 months ago by frosas

Changed 7 months ago by jwage

  • version changed from 0.10 to 0.11
  • milestone changed from 0.11.1 to 0.11.0

Changed 6 months ago by guilhermeblanco

  • milestone changed from 0.11.0 to 1.0.0-BETA1

Hi...

Your ticket is almost right. It only fails in one point. I'll not consider the case that the query is wrong.
Currently, AND has precedence over OR. This is what the manual describes and indeed is what happens in Doctrine. That's what Doctrine does, CURRENTLY.

The fact is that OR should have precedence over AND (your wish), but as I told you, now OR accepts only one expression which means it'll always behave like I told you.
We can't fix that for 0.X or 1.X, but this change is already made in 2.X (which will be released next year). I did a simple check and applied your fix. It broke some tests and also broke a lot of code in 2 projects I tried.
So, I have to tell you we cannot fix it for 0.X, but we're studying the possibility to apply it in 1.X. It's fact that this change will be active in 2.X, so it'll reality in the future, I just don't know when.

I'm moving your ticket to 1.0, since we're considering this change there.

Changed 6 months ago by guilhermeblanco

  • milestone changed from 1.0.0-BETA1 to 1.0.0

Changed 6 months ago by jwage

  • milestone changed from 1.0.0 to 0.12.0

Changed 5 months ago by jwage

  • status changed from new to closed
  • resolution set to fixed

(In [4683]) fixes #939

Changed 3 months ago by anonymous

  • milestone New deleted

Milestone New deleted

Note: See TracTickets for help on using tickets.