Comparing version 2.1.27 to 2.1.28
@@ -0,1 +1,4 @@ | ||
### v2.1.28 | ||
- Ensure hasMany associations work when properties have mapsTo (#679) | ||
### v2.1.27 | ||
@@ -2,0 +5,0 @@ - Fix noisy mysql debug output (#642) |
@@ -135,2 +135,13 @@ var _ = require("lodash"); | ||
function adjustForMapsTo(options) { | ||
// Loop through the (cloned) association model id fields ... some of them may've been mapped to different | ||
// names in the actual database - if so update to the mapped database column name | ||
for(i=0; i<options.__merge.to.field.length; i++) { | ||
var idProp = association.model.properties[options.__merge.to.field[i]]; | ||
if(idProp && idProp.mapsTo) { | ||
options.__merge.to.field[i] = idProp.mapsTo; | ||
} | ||
} | ||
} | ||
Object.defineProperty(Instance, association.hasAccessor, { | ||
@@ -153,5 +164,8 @@ value: function () { | ||
from: { table: association.mergeTable, field: Object.keys(association.mergeAssocId) }, | ||
to: { table: association.model.table, field: association.model.id }, | ||
to: { table: association.model.table, field: association.model.id.slice(0) }, // clone model id | ||
where: [ association.mergeTable, {} ] | ||
}; | ||
adjustForMapsTo(options); | ||
options.extra = association.props; | ||
@@ -236,8 +250,11 @@ options.extra_info = { | ||
from : { table: association.mergeTable, field: Object.keys(association.mergeAssocId) }, | ||
to : { table: association.model.table, field: association.model.id }, | ||
to : { table: association.model.table, field: association.model.id.slice(0) }, // clone model id | ||
where : [ association.mergeTable, {} ] | ||
}; | ||
options.extra = association.props; | ||
options.extra_info = { | ||
table: association.mergeTable, | ||
adjustForMapsTo(options); | ||
options.extra = association.props; | ||
options.extra_info = { | ||
table: association.mergeTable, | ||
id: util.values(Instance, Model.id), | ||
@@ -244,0 +261,0 @@ id_prop: Object.keys(association.mergeId), |
@@ -15,3 +15,3 @@ { | ||
], | ||
"version" : "2.1.27", | ||
"version" : "2.1.28", | ||
"license" : "MIT", | ||
@@ -47,12 +47,12 @@ "homepage" : "http://dresende.github.io/node-orm2", | ||
"devDependencies": { | ||
"mysql" : "2.5.5", | ||
"mysql" : "2.9.0", | ||
"pg" : "4.3.0", | ||
"sqlite3" : "3.0.5", | ||
"async" : "0.9.0", | ||
"mocha" : "1.13.0", | ||
"async" : "1.5.0", | ||
"mocha" : "2.3.3", | ||
"should" : "1.2.2", | ||
"mongodb" : "1.3.19", | ||
"glob" : "3.2.8" | ||
"glob" : "5.0.15" | ||
}, | ||
"optionalDependencies": {} | ||
} |
Sorry, the diff of this file is not supported yet
235775
6001