dresende / node-orm2

Object Relational Mapping
http://github.com/dresende/node-orm2
MIT License
3.07k stars 379 forks source link

Aggregate alias error #705

Closed edpop closed 7 years ago

edpop commented 8 years ago

Hello.

I tried to aggregate a simple table: { id: serial, id_state: integer } myModel.aggregate(["id_state"]).max("id").as("my_name").groupBy("id_state")

Got error: { "code": "Unknown", "message": "Cannot set property 'alias' of undefined" }

There is a line: https://github.com/dresende/node-orm2/blob/v2.1.30/lib/AggregateFunctions.js#L24 When i removed this, that line began to work correctly: https://github.com/dresende/node-orm2/blob/v2.1.30/lib/AggregateFunctions.js#L71

node -v: v4.2.1 db: postgresql 9.4 orm: 2.1.30

By the way, it would be nice to add "ARRAY_AGG" in https://github.com/dresende/node-orm2/blob/v2.1.30/lib/Drivers/DML/postgres.js#L109. It works fine on my config.

Thank you.