Doctrine 1
  1. Doctrine 1
  2. DC-424

using boolean logic in select don't work

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.1.6, 1.2.1
    • Fix Version/s: None
    • Component/s: Query
    • Labels:
      None

      Description

      Continuing with same setup as in http://www.doctrine-project.org/jira/browse/DC-417
      I discovered another issue

      $result = Doctrine_Query::create()
          ->select('u.*, m.*, COUNT(m.id) > 0 AS match_check')
          ->from('User u')
          ->leftJoin('u.Matches m')
          ->groupBy('u.id')
          ->orderBy('match_check DESC, RAND()')
          ->execute(array(), Doctrine::HYDRATE_ARRAY);
      

      match_check will actually be count of matches not 0 or 1 as i expected.
      is it bug or feature?

        Activity

        Hide
        Guilherme Blanco added a comment -

        SelectExpressions cannot contain ComparisonExpressions.

        That's a limitation of Doctrine 1, which was resolved in Doctrine 2.

        Cheers,

        Show
        Guilherme Blanco added a comment - SelectExpressions cannot contain ComparisonExpressions. That's a limitation of Doctrine 1, which was resolved in Doctrine 2. Cheers,
        Hide
        Josh Boyd added a comment - - edited

        Something like this will work:

        $result = Doctrine_Query::create()
            ->select('u.*, m.*)
            ->addSelect("QUOTE(IF(COUNT(m.id) > 0),1,0)) match_check')
            ->from('User u')
            ->leftJoin('u.Matches m')
            ->groupBy('u.id')
            ->orderBy('match_check DESC, RAND()')
            ->execute(array(), Doctrine::HYDRATE_ARRAY);
        
        Show
        Josh Boyd added a comment - - edited Something like this will work: $result = Doctrine_Query::create() ->select('u.*, m.*) ->addSelect("QUOTE(IF(COUNT(m.id) > 0),1,0)) match_check') ->from('User u') ->leftJoin('u.Matches m') ->groupBy('u.id') ->orderBy('match_check DESC, RAND()') ->execute(array(), Doctrine::HYDRATE_ARRAY);

          People

          • Assignee:
            Guilherme Blanco
            Reporter:
            Ivo Võsa
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: