Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

group_concat with orderBy #978

Open
Mopster opened this issue Sep 14, 2017 · 1 comment
Open

group_concat with orderBy #978

Mopster opened this issue Sep 14, 2017 · 1 comment
Labels

Comments

@Mopster
Copy link

Mopster commented Sep 14, 2017

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 ?

@DonCallisto
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants