Details

    • Type: New Feature New Feature
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Duplicate
    • Affects Version/s: Git Master
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      any

      Description

      Note: I used critical priority for this issue because this is one of the most criticised things about Doctrine 2 worldwide.


      The worst thing about Doctrine 2 is, that you can do almost nothing through methods like Category::getArticles();.
      For example, you have the Category and want to output all the articles. Fine, nothing easier:

      foreach ($category->getArticles() as $article) {
      echo $article->name;
      }

      OK. And now I need only "visible" articles (others are hidden for now). And here it is. You need DQL even for this easy task. Without DQL you can't do nothing, but using DQL (or QueryBuilder) everywhere is very very bad. Simply there is no way to write method like getVisibleArticles(). (Except selecting all and using some filter, but that's nonsense.)

      The solution would be some kind of smart collections (but i don't mind if you come up with something different):

      public function getArticles($visibility = 0, $limit = NULL) {
      return $this->articles->filter('visibility', $visibility)->limit($limit);
      }

      Of course when you need any AND, OR, XOR, IN, LIKE and so DQL is needed. This should be for some simple things only.

        Issue Links

          Activity

          Hide
          Benjamin Eberlei added a comment -

          1. Assocations are not loaded through DQL but through the Persisters.
          2. In DQL you can do SELECT a FROM Article a JOIN a.comments c WITH c.status = 'active' ...
          3 . With Doctrine 2.1-DEV you can mark an association as EXTRA_LAZY and use Article::$comments->slice($count, $offset) to fetch only parts of the association.

          Show
          Benjamin Eberlei added a comment - 1. Assocations are not loaded through DQL but through the Persisters. 2. In DQL you can do SELECT a FROM Article a JOIN a.comments c WITH c.status = 'active' ... 3 . With Doctrine 2.1-DEV you can mark an association as EXTRA_LAZY and use Article::$comments->slice($count, $offset) to fetch only parts of the association.
          Hide
          Parl Johnson added a comment - - edited

          So based on my clarification above, how do you suggest I call a DQL from inside of an entity? Call it inline in one my methods through an entity manager? or through an entity manager to a custom repository? I don't see any other ways, am I missing anything? My problem is the reverse of what you are solving with Extra Lazy Loading, I need a collection to stay empty based on a my DQL, but it won't! It keeps calling all associations.

          Show
          Parl Johnson added a comment - - edited So based on my clarification above, how do you suggest I call a DQL from inside of an entity? Call it inline in one my methods through an entity manager? or through an entity manager to a custom repository? I don't see any other ways, am I missing anything? My problem is the reverse of what you are solving with Extra Lazy Loading, I need a collection to stay empty based on a my DQL, but it won't! It keeps calling all associations.
          Hide
          Jáchym Toušek added a comment -

          Hi, is there a way to implement this in current Doctrine? I'm talking about this method (it should be a method of CategoryEntity):

          public function getArticles($visibility = 0, $limit = NULL)

          { return /* what should be here? */ }
          Show
          Jáchym Toušek added a comment - Hi, is there a way to implement this in current Doctrine? I'm talking about this method (it should be a method of CategoryEntity): public function getArticles($visibility = 0, $limit = NULL) { return /* what should be here? */ }
          Hide
          Koby Soto added a comment -

          A year later this is still highly required feature.

          Show
          Koby Soto added a comment - A year later this is still highly required feature.
          Hide
          Alexandre Salomé added a comment -
          Show
          Alexandre Salomé added a comment - Found this in documentation, related to this ticket: http://docs.doctrine-project.org/en/latest/reference/working-with-associations.html#filtering-collections

            People

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

              Dates

              • Created:
                Updated:
                Resolved: