DDC-2851: Allow set custom collection initializer at runtime #3606

doctrinebot opened this Issue Dec 12, 2013 · 0 comments

2 participants


Jira issue originally created by user koc:

Use case: Company, Category, CompanyCategory entities. We are loading set of companies and should initialize Company.companyCategories collection with joined categories, which ordered by Company.title.

I cann't do it via Criteria API, it doesn't supports joins. + I should return same PersistentCollection instance (Company.companyCategories used in Symfony2 forms).

Current workaround:

    public function loadCompanyCategoriesCollectionForCompany(Company $company)
        $companyCategories = $this->_em->createQueryBuilder()
            ->from('OloloCompaniesBundle:CompanyCategory', 'cc')
            ->join('cc.category', 'c')
            ->where('cc.company = :company')
            ->setParameter('company', $company)

        $coll = $company->getCompanyCategories();
        foreach ($companyCategories as $companyCategory) { /** @var $coll \Doctrine\ORM\PersistentCollection **/

What would be nice: native API for setting custom initializers.

@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment