Doctrine 1
  1. Doctrine 1
  2. DC-962

Broken logic when doctrine translates limit's into subqueries, with joins. (with patch)

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Blocker Blocker
    • Resolution: Unresolved
    • Affects Version/s: 1.2.3
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:
      All

      Description

      Problem exists when Doctrine formulates a subquery to perform a limit when a join in included.

      The problem is that the where clause that doctrine creates for the subquery (the WHERE IN clause) is inserted as the first where clause.
      This will break the parameter duplicate done at Doctrine_Query_Abstract:969, as the order of the parameters is now wrong.

      Consider:

       
      select * from table
      join metadata WITH c = ?
      where a = ? and b = ?
      limit 1
      

      with parameters be (1, 2, 3)

      Doctrine will translate this to

       
      select * from table
      join metadata WITH c = ?
      where table.id IN (
          select id from table
          join metadata WITH c = ?
          where a = ? and b = ?
          limit 1
      )
      and a = ? and b = ?
      

      Doctrine will duplicate the params (Doctrine_Query_Abstract:969) to (1, 2, 3, 1, 2, 3), but now they are in the wrong order completely.
      They should be (1,1,2,3,2,3).

      The easy fix is to move the limit subquery to the LAST where clause, which would reuslt in a query like so:

       
      select * from table
      join metadata WITH c = ?
      where a = ? and b = ?
      and table.id IN (
          select id from table
          join metadata WITH c = ?
          where a = ? and b = ?
          limit 1
      )
      

      Attached is a patch to fix this issue, along with a patch that fixes all unit tests referring to the old query format.

      1. Query.php.patch
        1 kB
        Ben Davies
      2. Tests.patch
        17 kB
        Ben Davies

        Activity

        Hide
        Ben Davies added a comment -

        upping to blocker since this breaks very basic queries

        Show
        Ben Davies added a comment - upping to blocker since this breaks very basic queries

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Ben Davies
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: