dresende / node-orm2

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

Should aggregate argument take model's property names? #735

Open rathapolk opened 8 years ago

rathapolk commented 8 years ago

I have this model ..

db.define('schoolSettings', {
        id:             { type: 'text', size: 36, key: true, mapsTo: 'id' },
        schoolId:       { type: 'text', size: 36, required: true, mapsTo: 'school_id' },
        ordering:       { type: 'integer', required: true, mapsTo: 'ordering' },
        settingName:    { type: 'text', size: 20, required: true, mapsTo: 'setting_name' },
        settingValue:   { type: 'text', size: 500, mapsTo: 'setting_value' }
    }, {
        collection: 'school_settings'
});

I wrote aggregate code this way...

SchoolSettings.aggregate({ schoolId: id }).max('ordering').get(function (err, max) { console.log(max); }

It prints 'undefined' which is incorrect since there are data rows in the database.

Later, I changed the model's property name 'schoolId' to actual column name in database 'school_id'. Then It works.

SchoolSettings.aggregate({ school_id: id }).max('ordering').get(function (err, max) { console.log(max); }

Should this function take model's property names instead of actual column names?

Regards, Rathapol K.

dxg commented 8 years ago

Yes, it's a bug.