abstratt / cloudfier

Cloudfier is a model-driven tool for rapid development of business applications
http://cloudfier.com
Other
22 stars 4 forks source link

missing grouping when collecting where expression involves aggregation via derivation #82

Open abstratt opened 8 years ago

abstratt commented 8 years ago

In the source model below:

class State
    derived attribute population : Integer := {
        self.cities.sum((c : City) : Integer { c.population })
    };

    static query statePopulations() : StatePopulation[*];
    begin
        return State extent.collect((cityState : State) : StatePopulation {
            ({
                abbreviation := cityState.abbreviation, 
                population := cityState.population
            } as StatePopulation)
        });
    end;

even though there is no explicit grouping, that is what is actually happening, because State.population is a derived property that is modeled as an aggregation.

The generator currently cannot handle that.

abstratt commented 8 years ago

This is a way to rewrite the model above that expresses the grouping explicitly:

    static query statePopulationsViaCities() : StatePopulation[*];
    begin
        return City extent.groupBy((c : City) : State {
            c.cityState
        }).groupCollect((cities : City[*]) : StatePopulation {
            {
                abbreviation := cities.one().cityState.abbreviation, 
                population := cities.sum((c : City) : Integer { c.population })
            }
        });
    end;

(which is supported by the JPQL generator).