Skip to content
This repository has been archived by the owner on Nov 11, 2020. It is now read-only.

Allow using operators in group stages #256

Merged
merged 1 commit into from
Mar 18, 2016

Conversation

alcaeus
Copy link
Member

@alcaeus alcaeus commented Mar 18, 2016

Fixes #254.

This change allows users to use operators in group stages for the ID field:

$builder
    ->group()
        ->field('_id')
        ->year('$dateField')
        ->field('count')
        ->sum(1);

Note: this will also allow building the following pipeline which is invalid and will error out on MongoDB when executed:

$builder
    ->group()
        ->field('_id')
        ->year('$dateField')
        ->field('month')
        ->month('$dateField');

I've decided against checking for this as this would require overwriting all operators declared in the Operator class to check whether the current field is an ID field and error out if it's not. People familiar with aggregation queries should be able to make this distinction on their own.

@alcaeus alcaeus added this to the 1.3.0 milestone Mar 18, 2016
@jmikola
Copy link
Member

jmikola commented Mar 18, 2016

LGTM.

alcaeus added a commit that referenced this pull request Mar 18, 2016
@alcaeus alcaeus merged commit ab3e697 into doctrine:master Mar 18, 2016
@alcaeus alcaeus deleted the aggregation-group-allow-operators branch March 18, 2016 18:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants