Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2319

[GH-590] DQL Query: process ArrayCollection values to ease development

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.5
    • Component/s: None
    • Security Level: All
    • Labels:
      None

      Description

      This issue is created automatically through a Github pull request on behalf of michaelperrin:

      Url: https://github.com/doctrine/doctrine2/pull/590

      Message:

      I added some code to ease "where in" parameter binding.

      As you know, when a where condition is added, the object itself can be passed as a parameter and it's id is automatically retrieved:

      ```php
      $queryBuilder = $this
      ->where('model.category = :category')
      ->setParameter('category', $category)
      ;
      ```
      Where `$category` is an object.

      But it doesn't work for collections:
      ```php
      $queryBuilder = $this
      ->where('model.category IN (:categories)')
      ->setParameter('categories', $categories)
      ;
      ```

      Where categories is an `ArrayCollection` object (retrieved from a many to one relation for instance).

      This doesn't work in the current version of Doctrine, and my PR solved that.

      So far, the only solution is to do the following:

      ```php
      $categoryIds = array();

      foreach ($categories as $category)

      { $categoryIds[] = $category->getId(); }

      $queryBuilder = $this
      ->where('model.category IN (:category_ids)')
      ->setParameter('category_ids', $categoryIds)
      ;
      ```

      And this is pretty borring when you have to do it several times for several entities.

      Note that I didn't add any unit test for this feature. Can you explain me where I should add the test?

      Thanks!

        Activity

        Benjamin Eberlei created issue -
        Benjamin Eberlei made changes -
        Field Original Value New Value
        Issue Type Bug [ 1 ] Improvement [ 4 ]
        Hide
        Doctrine Bot added a comment -

        A related Github Pull-Request [GH-590] was closed:
        https://github.com/doctrine/doctrine2/pull/590

        Show
        Doctrine Bot added a comment - A related Github Pull-Request [GH-590] was closed: https://github.com/doctrine/doctrine2/pull/590
        Show
        Marco Pivetta added a comment - Merged: https://github.com/doctrine/doctrine2/commit/423ea00539d11e9a12e952a7e9144bd2c53019dc
        Marco Pivetta made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Assignee Benjamin Eberlei [ beberlei ] Guilherme Blanco [ guilhermeblanco ]
        Fix Version/s 2.5 [ 10522 ]
        Resolution Fixed [ 1 ]

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-2319, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Guilherme Blanco
            Reporter:
            Benjamin Eberlei
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: