不要怂,就是干,撸起袖子干!

Commit 83e08fce by Jisoo Park

reuse existing DAO.identifiers

1 parent c7bee173
Showing with 5 additions and 5 deletions
......@@ -284,14 +284,14 @@ module.exports = (function() {
associationData.forEach(function(data) {
var daoInstance = associatedDaoFactory.build(data, { isNewRecord: false })
, identifier = associatedDaoFactory.hasPrimaryKeys ? Utils.firstKeyOfHash(associatedDaoFactory.primaryKeys) : 'id'
, isEmpty = ! Utils.firstValueOfHash(daoInstance.identifiers)
if (['BelongsTo', 'HasOne'].indexOf(association.associationType) > -1) {
accessor = Utils.singularize(accessor)
dao[accessor] = daoInstance[identifier] ? daoInstance : null
dao[accessor] = isEmpty ? null : daoInstance
} else {
dao[accessor] = dao[accessor] || []
if (daoInstance[identifier])
if (! isEmpty)
dao[accessor].push(daoInstance)
}
})
......
......@@ -149,10 +149,10 @@ var Utils = module.exports = {
}
},
firstKeyOfHash: function(obj) {
firstValueOfHash: function(obj) {
for (var key in obj) {
if (obj.hasOwnProperty(key))
return key
return obj[key]
}
return null
},
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!