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

          People

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

            Dates

            • Created:
              Updated: