You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Person.aggregate({country: "US"}).select("age")// the previous syntax is still available; to pass more properties just pass an Array or each one as a different argument.avg("weight").groupBy("age").order("name","Z").get(function(err,groups){// groups should have "age" and "avg_weight"});
I'm worrying about that, '.order("name", "Z")' which the 'name' is an existing table column, what about 'order("w", "Z")'? The 'w' is avg("weight") in my example above.
Just something to be aware of: mysql doesn't follow the sql standard and helps you out a bit with invalid queries; any fields which are in the order statement must also be included in the groupBy one.
This is a very common bug, I've seen it come up in every ORM I've ever used, and the internets is littered with examples of this.
Here it's not a huge problem since you can just add .select('name') to the query and it'll work, but I imagine someone will open an issue over this sooner or later.
Activity
dresende commentedon Apr 11, 2013
I think this is possible:
The only thing still missing is the order.
dresende commentedon Apr 11, 2013
One thing I will probably allow is to define additional properties after the
.aggregate()so the syntax gets more clear to read.huangyingjie commentedon Apr 11, 2013
Good! Maybe I shall try to read the source code. I will expect the order.
dresende commentedon Apr 11, 2013
Coming right out! Just doing the unit tests.
Adds possibility of order to aggregate method (#114)
Adds .select() aggregate function to support additional properties to…
dresende commentedon Apr 11, 2013
Now this is possible:
huangyingjie commentedon Apr 11, 2013
so efficient.
huangyingjie commentedon Apr 11, 2013
I'm worrying about that, '.order("name", "Z")' which the 'name' is an existing table column, what about 'order("w", "Z")'? The 'w' is avg("weight") in my example above.
dxg commentedon Apr 11, 2013
Just something to be aware of: mysql doesn't follow the sql standard and helps you out a bit with invalid queries; any fields which are in the
orderstatement must also be included in thegroupByone.This is a very common bug, I've seen it come up in every ORM I've ever used, and the internets is littered with examples of this.
Here it's not a huge problem since you can just add
.select('name')to the query and it'll work, but I imagine someone will open an issue over this sooner or later.dresende commentedon Apr 11, 2013
Thank you for pointing that out. I'll keep that in mind when changing #115 .