group_concat with orderBy
Hi,
I'm trying to order the data in a group_concat but can't figure out how to do it.
Email is an ORM entity with a isPrimary boolean. I need the primary email addresses to be first. In the grid (export) the ORM orderBy is ignored.
/**
* A Person can have many Emails.
*
* @ORM\OneToMany(targetEntity="Email", mappedBy="person", cascade={"persist", "remove"}, orphanRemoval=true)
* @ORM\OrderBy({"isPrimary" = "DESC", "inactive" = "ASC"})
* @Grid\Column(field="emails.value:group_concat:order_by:emails.isPrimary:desc", title="email", visible=false, export=true) // primary emailaddress
* @Grid\Column(field="emails.value:group_concat:distinct", title="all emails", visible=false, export=true)
* @Assert\Count(min = "1", groups={"Preregistration", "Registration", "Custom"}),
*/
protected $emails;
I tried several syntax versions of emails.value:group_concat:order_by:emails.isPrimary:desc but no so far no luck. the group_concat seems to support an orderBy property : https://github.com/beberlei/DoctrineExtensions/pull/111/files
Is this supported ? If so, how do I use it ? If not, is there another way I can get the emails sorted correctly ?
You can initialize source with a QueryBuilder that extract data ordered with this fashion.
So something like
$source = new GridEntity('VendoBundle:Entity');
$qb = $this
->getDoctrine()
->getRepository('VendoBundle:Entity')
->getAQueryBuilder();
$source->initQueryBuilder($qb);
$grid->setSource($source);
Of course doing it in annotation could be smarter and easier to reuse everywhere but, ATM, I don't know if it works or not. I should check properly but I don't have much time this period.