Skip to content

Commit

Permalink
Adds possibility to add order to hasMany getAccessor (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
dresende committed Mar 4, 2013
1 parent d838876 commit 742212c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/Associations/Many.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ function extendInstance(Model, Instance, Driver, association, opts, cb) {
var conditions = null;
var options = {};
var limit;
var order = null;
var cb = null;

for (var i = 0; i < arguments.length; i++) {
Expand All @@ -147,7 +148,12 @@ function extendInstance(Model, Instance, Driver, association, opts, cb) {
if (conditions === null) {
conditions = arguments[i];
} else {
options = arguments[i];
if (Array.isArray(arguments[i])) {
order = arguments[i];
order[0] = association.model.table + "." + order[0];
} else {
options = arguments[i];
}
}
break;
case "number":
Expand All @@ -167,6 +173,9 @@ function extendInstance(Model, Instance, Driver, association, opts, cb) {
id_prop: association.mergeId,
assoc_prop: association.mergeAssocId
};
if (order !== null) {
options.order = order;
}

if (conditions === null) {
conditions = {};
Expand Down

0 comments on commit 742212c

Please sign in to comment.