Skip to content

Commit d1d6ba5

Browse files
committed
DRY up code & convert spaces to tabs
1 parent 8f2d4e1 commit d1d6ba5

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

lib/Associations/Many.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,17 @@ function extendInstance(Model, Instance, Driver, association, opts, createInstan
132132
});
133133
}
134134

135+
function adjustForMapsTo(options) {
136+
// Loop through the (cloned) association model id fields ... some of them may've been mapped to different
137+
// names in the actual database - if so update to the mapped database column name
138+
for(i=0; i<options.__merge.to.field.length; i++) {
139+
var idProp = association.model.properties[options.__merge.to.field[i]];
140+
if(idProp && idProp.mapsTo) {
141+
options.__merge.to.field[i] = idProp.mapsTo;
142+
}
143+
}
144+
}
145+
135146
Object.defineProperty(Instance, association.hasAccessor, {
136147
value: function () {
137148
var Instances = Array.prototype.slice.apply(arguments);
@@ -153,14 +164,7 @@ function extendInstance(Model, Instance, Driver, association, opts, createInstan
153164
where: [ association.mergeTable, {} ]
154165
};
155166

156-
// Loop through the (cloned) association model id fields ... some of them may've been mapped to different
157-
// names in the actual database - if so update to the mapped database column name
158-
for(i=0; i<options.__merge.to.field.length; i++) {
159-
var idProp = association.model.properties[options.__merge.to.field[i]];
160-
if(idProp && idProp.mapsTo) {
161-
options.__merge.to.field[i] = idProp.mapsTo;
162-
}
163-
}
167+
adjustForMapsTo(options);
164168

165169
options.extra = association.props;
166170
options.extra_info = {
@@ -245,14 +249,7 @@ function extendInstance(Model, Instance, Driver, association, opts, createInstan
245249
where : [ association.mergeTable, {} ]
246250
};
247251

248-
// Loop through the (cloned) association model id fields ... some of them may've been mapped to different
249-
// names in the actual database - if so update to the mapped database column name
250-
for(i=0; i<options.__merge.to.field.length; i++) {
251-
var idProp = association.model.properties[options.__merge.to.field[i]];
252-
if(idProp && idProp.mapsTo) {
253-
options.__merge.to.field[i] = idProp.mapsTo;
254-
}
255-
}
252+
adjustForMapsTo(options);
256253

257254
options.extra = association.props;
258255
options.extra_info = {

0 commit comments

Comments
 (0)