[DDC-2454] To-Many OrderBy mechanism should allow many-to-one associations Created: 16/May/13  Updated: 16/May/13

Status: Open
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: None
Fix Version/s: None
Security Level: All

Type: Improvement Priority: Minor
Reporter: Oleg Namaka Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: association, orderBy


 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;
}


Generated at Sat Oct 25 16:21:33 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.