Details

    • Type: New Feature New Feature
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: Git Master
    • Fix Version/s: None
    • Component/s: DQL, Mapping Drivers, ORM
    • Security Level: All
    • Labels:
      None

      Description

      I need some way to select a random row from a table. There was something like "ORDER BY RAND()" in SQL but I can't really find anything like that for Doctrine.

        Activity

        Hide
        Benjamin Eberlei added a comment -

        Doctrine allows you to execute SQL and hydrate objects from that using the Native Query API as described in the documentation.

        Show
        Benjamin Eberlei added a comment - Doctrine allows you to execute SQL and hydrate objects from that using the Native Query API as described in the documentation.
        Hide
        Glen Ainscow added a comment -

        I need this as well ... why can't we do something like:

        $qb->orderBy('RAND()');
        

        Or maybe something at a lower level, like:

        $qb->add('orderBy', new Expr\Func('RAND', array()));
        

        ?

        Show
        Glen Ainscow added a comment - I need this as well ... why can't we do something like: $qb->orderBy('RAND()'); Or maybe something at a lower level, like: $qb->add('orderBy', new Expr\Func('RAND', array())); ?
        Hide
        Peter Petrov added a comment -

        I need this as well! ORDER BY RAND() or something like this is a MUST HAVE for Doctrine! I do NOT want to fetch ALL then Hydrate ALL to select some rows, nor I want to do 2 queries in a row! Also, last one method actually can return 2 SAME records....

        Hope I see this soon. I'm using Symfony 2

        Show
        Peter Petrov added a comment - I need this as well! ORDER BY RAND() or something like this is a MUST HAVE for Doctrine! I do NOT want to fetch ALL then Hydrate ALL to select some rows, nor I want to do 2 queries in a row! Also, last one method actually can return 2 SAME records.... Hope I see this soon. I'm using Symfony 2
        Hide
        daslicht added a comment -

        +1 Please add this feature

        Show
        daslicht added a comment - +1 Please add this feature

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Jáchym Toušek
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: