Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2454

To-Many OrderBy mechanism should allow many-to-one associations

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All

      Description

      class ProductCategory
      {
          /**
           * Store
           *
           * @var Store
           *
           * @ORM\ManyToOne(targetEntity="Store")
           * @ORM\JoinColumn(name="store_id", referencedColumnName="store_id")
           */
          private $Store;
      
          /**
           * storeId (for ordering in Product::ProductCategories only)
           *
           * @var integer
           *
           * @ORM\Column(name="store_id", type="integer")
           */
          private $storeId;
      ...
      
      class Product
      {
          /**
           * Associated categories
           *
           * @var \Doctrine\Common\Collections\Collection
           *
           * @ORM\OneToMany(targetEntity="ProductCategory", mappedBy="Product")
           * @ORM\OrderBy({"storeId"="ASC"})
           */
          private $ProductCategories;
      }
      }
      

      If it is possible now to sort the ProductCategories collection by the storeId field, it should also be possible to sort them by the Store association. Currently a set of two fields is required: Store as a regular Many-To-One association and if a need arises to be able to use it to sort the One-To-Many collections then storeId needs to be added to the ProductCategory entity. In that case the ProductCategory entity does not pass the schema validation but is perfectly usable.

      This should be allowed:

      class Product
      {
          /**
           * Associated categories
           *
           * @var \Doctrine\Common\Collections\Collection
           *
           * @ORM\OneToMany(targetEntity="ProductCategory", mappedBy="Product")
           * @ORM\OrderBy({"Store"="ASC"})
           */
          private $ProductCategories;
      }
      
      

        Activity

        Oleg Namaka created issue -
        Oleg Namaka made changes -
        Field Original Value New Value
        Component/s ORM [ 10012 ]
        Oleg Namaka made changes -
        Labels association orderBy
        Oleg Namaka made changes -
        Description {code}
        class ProductCategory
        {
            /**
             * Store
             *
             * @var Store
             *
             * @ORM\ManyToOne(targetEntity="Store")
             * @ORM\JoinColumn(name="store_id", referencedColumnName="store_id")
             */
            private $Store;

            /**
             * storeId (for ordering in Product::ProductCategories only)
             *
             * @var integer
             *
             * @ORM\Column(name="store_id", type="integer")
             */
            protected $storeId;
        ...

        class Product
        {
            /**
             * Associated categories
             *
             * @var \Doctrine\Common\Collections\Collection
             *
             * @ORM\OneToMany(targetEntity="ProductCategory", mappedBy="Product")
             * @ORM\OrderBy({"storeId"="ASC"})
             */
            protected $ProductCategories;
        }
        }
        {code}
        If it is possible now to sort the ProductCategories collection by the storeId field, it should also be possible to sort them by the Store association. Currently a set of two fields is required: Store as a regular Many-To-One association and if a need arises to be able to use it to sort the One-To-Many collections then storeId needs to be added to the ProductCategory entity. In that case the ProductCategory entity does not pass the schema validation but is perfectly usable.

        This should be allowed:
        {code}
        class Product
        {
            /**
             * Associated categories
             *
             * @var \Doctrine\Common\Collections\Collection
             *
             * @ORM\OneToMany(targetEntity="ProductCategory", mappedBy="Product")
             * @ORM\OrderBy({"Store"="ASC"})
             */
            protected $ProductCategories;
        }

        {code}
        {code}
        class ProductCategory
        {
            /**
             * Store
             *
             * @var Store
             *
             * @ORM\ManyToOne(targetEntity="Store")
             * @ORM\JoinColumn(name="store_id", referencedColumnName="store_id")
             */
            private $Store;

            /**
             * storeId (for ordering in Product::ProductCategories only)
             *
             * @var integer
             *
             * @ORM\Column(name="store_id", type="integer")
             */
            private $storeId;
        ...

        class Product
        {
            /**
             * Associated categories
             *
             * @var \Doctrine\Common\Collections\Collection
             *
             * @ORM\OneToMany(targetEntity="ProductCategory", mappedBy="Product")
             * @ORM\OrderBy({"storeId"="ASC"})
             */
            private $ProductCategories;
        }
        }
        {code}
        If it is possible now to sort the ProductCategories collection by the storeId field, it should also be possible to sort them by the Store association. Currently a set of two fields is required: Store as a regular Many-To-One association and if a need arises to be able to use it to sort the One-To-Many collections then storeId needs to be added to the ProductCategory entity. In that case the ProductCategory entity does not pass the schema validation but is perfectly usable.

        This should be allowed:
        {code}
        class Product
        {
            /**
             * Associated categories
             *
             * @var \Doctrine\Common\Collections\Collection
             *
             * @ORM\OneToMany(targetEntity="ProductCategory", mappedBy="Product")
             * @ORM\OrderBy({"Store"="ASC"})
             */
            private $ProductCategories;
        }

        {code}
        Marco Pivetta made changes -
        Priority Major [ 3 ] Minor [ 4 ]

        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-2454, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Oleg Namaka
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: