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

Commit d81e4937 by Mick Hansen

chore: rename include.daoFactory to include.model

1 parent 57073848
......@@ -362,7 +362,7 @@ module.exports = (function() {
, self = this
, accessor = Utils._.camelize(key)
, childOptions
, primaryKeyAttribute = include.daoFactory.primaryKeyAttribute
, primaryKeyAttribute = include.model.primaryKeyAttribute
, isEmpty = value[0] && value[0][primaryKeyAttribute] === null
if (!isEmpty) {
......@@ -383,9 +383,9 @@ module.exports = (function() {
if (association.isSingleAssociation) {
accessor = Utils.singularize(accessor, self.Model.options.language)
self[accessor] = self.dataValues[accessor] = isEmpty ? null : include.daoFactory.build(value[0], childOptions)
self[accessor] = self.dataValues[accessor] = isEmpty ? null : include.model.build(value[0], childOptions)
} else {
self[accessor] = self.dataValues[accessor] = isEmpty ? [] : include.daoFactory.bulkBuild(value, childOptions)
self[accessor] = self.dataValues[accessor] = isEmpty ? [] : include.model.bulkBuild(value, childOptions)
}
};
......
var Utils = require("../../utils")
, SqlString = require("../../sql-string")
, daoFactory = require("../../model")
, Model = require("../../model")
, _ = require('lodash')
module.exports = (function() {
......@@ -396,7 +396,7 @@ module.exports = (function() {
Strings: should proxy to quoteIdentifiers
Arrays:
* Expects array in the form: [<model> (optional), <model> (optional),... String, String (optional)]
Each <model> can be a daoFactory or an object {model: DaoFactory, as: String}, matching include
Each <model> can be a model or an object {model: Model, as: String}, matching include
* Zero or more models can be included in the array and are used to trace a path through the tree of
included nested associations. This produces the correct table name for the ORDER BY/GROUP BY SQL
and quotes it.
......@@ -428,7 +428,7 @@ module.exports = (function() {
}
var model, as
if (item instanceof daoFactory) {
if (item instanceof Model) {
model = item
} else {
model = item.model
......@@ -581,7 +581,7 @@ module.exports = (function() {
- offset -> An offset value to start from. Only useable with limit!
*/
selectQuery: function(tableName, options, Model) {
selectQuery: function(tableName, options, model) {
// Enter and change at your own peril -- Mick Hansen
options = options || {}
......@@ -600,8 +600,8 @@ module.exports = (function() {
, subJoinQueries = []
, mainTableAs = null
if (!Array.isArray(tableName) && Model) {
options.tableAs = mainTableAs = this.quoteTable(Model.name)
if (!Array.isArray(tableName) && model) {
options.tableAs = mainTableAs = this.quoteTable(model.name)
}
options.table = table = !Array.isArray(tableName) ? this.quoteTable(tableName) : tableName.map(function(t) {
if (Array.isArray(t)) {
......@@ -611,8 +611,8 @@ module.exports = (function() {
}.bind(this)).join(", ")
if (subQuery && mainAttributes) {
if (Model.hasPrimaryKeys) {
Model.primaryKeyAttributes.forEach(function(keyAtt){
if (model.hasPrimaryKeys) {
model.primaryKeyAttributes.forEach(function(keyAtt){
if(mainAttributes.indexOf(keyAtt) == -1){
mainAttributes.push(keyAtt)
}
......@@ -663,7 +663,7 @@ module.exports = (function() {
if (options.include) {
var generateJoinQueries = function(include, parentTable) {
var table = include.daoFactory.getTableName()
var table = include.model.getTableName()
, as = include.as
, joinQueryItem = ""
, joinQueries = {
......@@ -697,7 +697,7 @@ module.exports = (function() {
}
if (through) {
var throughTable = through.daoFactory.getTableName()
var throughTable = through.model.getTableName()
, throughAs = as + "." + through.as
, throughAttributes = through.attributes.map(function(attr) {
return self.quoteIdentifier(throughAs) + "." + self.quoteIdentifier(attr) + " AS " + self.quoteIdentifier(throughAs + "." + attr)
......@@ -742,7 +742,7 @@ module.exports = (function() {
if (include.where) {
targetWhere = self.getWhereConditions(include.where, self.sequelize.literal(self.quoteIdentifier(as)), include.daoFactory, whereOptions)
targetWhere = self.getWhereConditions(include.where, self.sequelize.literal(self.quoteIdentifier(as)), include.model, whereOptions)
joinQueryItem += " AND "+ targetWhere
if (subQuery) {
if (!options.where) options.where = {}
......@@ -789,7 +789,7 @@ module.exports = (function() {
joinQueryItem += where
if (include.where) {
joinQueryItem += " AND "+self.getWhereConditions(include.where, self.sequelize.literal(self.quoteIdentifier(as)), include.daoFactory, whereOptions)
joinQueryItem += " AND "+self.getWhereConditions(include.where, self.sequelize.literal(self.quoteIdentifier(as)), include.model, whereOptions)
// If its a multi association we need to add a where query to the main where (executed in the subquery)
if (subQuery && association.isMultiAssociation && include.required) {
......@@ -851,7 +851,7 @@ module.exports = (function() {
// Add WHERE to sub or main query
if (options.hasOwnProperty('where')) {
options.where = this.getWhereConditions(options.where, mainTableAs || tableName, Model, options)
options.where = this.getWhereConditions(options.where, mainTableAs || tableName, model, options)
if (subQuery) {
subQueryItems.push(" WHERE " + options.where)
} else {
......@@ -861,7 +861,7 @@ module.exports = (function() {
// Add GROUP BY to sub or main query
if (options.group) {
options.group = Array.isArray(options.group) ? options.group.map(function (t) { return this.quote(t, Model) }.bind(this)).join(', ') : options.group
options.group = Array.isArray(options.group) ? options.group.map(function (t) { return this.quote(t, model) }.bind(this)).join(', ') : options.group
if (subQuery) {
subQueryItems.push(" GROUP BY " + options.group)
} else {
......@@ -871,7 +871,7 @@ module.exports = (function() {
// Add HAVING to sub or main query
if (options.hasOwnProperty('having')) {
options.having = this.getWhereConditions(options.having, tableName, Model, options, false)
options.having = this.getWhereConditions(options.having, tableName, model, options, false)
if (subQuery) {
subQueryItems.push(" HAVING " + options.having)
} else {
......@@ -886,10 +886,10 @@ module.exports = (function() {
if (Array.isArray(options.order)) {
options.order.forEach(function (t) {
if (subQuery && !(t[0] instanceof daoFactory) && !(t[0].model instanceof daoFactory)) {
subQueryOrder.push(this.quote(t, Model))
if (subQuery && !(t[0] instanceof Model) && !(t[0].model instanceof Model)) {
subQueryOrder.push(this.quote(t, model))
}
mainQueryOrder.push(this.quote(t, Model))
mainQueryOrder.push(this.quote(t, model))
}.bind(this))
} else {
mainQueryOrder.push(options.order)
......
......@@ -232,7 +232,7 @@ module.exports = (function() {
// Queries with include
} else if (this.options.hasJoin === true) {
results = groupJoinData(results, {
daoFactory: this.callee,
model: this.callee,
includeMap: this.options.includeMap,
includeNames: this.options.includeNames
}, {
......@@ -359,8 +359,8 @@ module.exports = (function() {
if (includeOptions.includeNames) {
calleeDataIgnore = calleeDataIgnore.concat(includeOptions.includeNames)
}
if (includeOptions.daoFactory.primaryKeyAttributes.length === 1) {
primaryKeyAttribute = includeOptions.daoFactory.primaryKeyAttribute
if (includeOptions.model.primaryKeyAttributes.length === 1) {
primaryKeyAttribute = includeOptions.model.primaryKeyAttribute
}
data.forEach(function parseRow(row) {
......
......@@ -1563,8 +1563,8 @@ module.exports = (function() {
// Apply on each include
if ( options.include && options.include.length ) {
options.include.forEach(function(include) {
if( typeof include == 'object' && include.daoFactory || include.daoFactory ){
paranoidClause.call( include.daoFactory || include.daoFactory, include )
if( typeof include == 'object' && include.model || include.model ){
paranoidClause.call( include.model || include.model, include )
}
})
}
......@@ -1667,13 +1667,13 @@ module.exports = (function() {
// convert all included elements to { Model: Model } form
var includes = options.include = options.include.map(function(include) {
if (include instanceof Model) {
return { daoFactory: include }
include = { model: include }
} else if (typeof include !== 'object') {
throw new Error('Include unexpected. Element has to be either an instance of Model or an object.')
} else if (include.hasOwnProperty('model')) {
include.daoFactory = include.model
delete include.model
} else if (include.hasOwnProperty('daoFactory')) {
include.model = include.daoFactory
}
return include
})
......@@ -1715,24 +1715,24 @@ module.exports = (function() {
}
var validateIncludedElement = function(include, tableNames) {
if (!include.hasOwnProperty('daoFactory')) {
if (!include.hasOwnProperty('model')) {
throw new Error('Include malformed. Expected attributes: model')
}
tableNames[include.daoFactory.tableName] = true
tableNames[include.model.tableName] = true
if (include.hasOwnProperty('attributes')) {
include.originalAttributes = include.attributes;
include.attributes = include.attributes.concat(include.daoFactory.primaryKeyAttributes)
include.attributes = include.attributes.concat(include.model.primaryKeyAttributes)
} else {
include.attributes = Object.keys(include.daoFactory.attributes)
include.attributes = Object.keys(include.model.attributes)
}
// pseudo include just needed the attribute logic, return
if (include._pseudo) return include
// check if the current Model is actually associated with the passed Model - or it's a pseudo include
var association = this.getAssociation(include.daoFactory, include.as)
var association = this.getAssociation(include.model, include.as)
if (association) {
include.association = association
include.as = association.as
......@@ -1743,7 +1743,7 @@ module.exports = (function() {
var through = include.association.through
include.through = {
daoFactory: through,
model: through,
as: Utils.singularize(through.tableName, through.options.language),
association: {
isSingleAssociation: true
......@@ -1761,12 +1761,12 @@ module.exports = (function() {
// Validate child includes
if (include.hasOwnProperty('include')) {
validateIncludedElements.call(include.daoFactory, include, tableNames)
validateIncludedElements.call(include.model, include, tableNames)
}
return include
} else {
var msg = include.daoFactory.name
var msg = include.model.name
if (include.as) {
msg += " (" + include.as + ")"
......@@ -1846,7 +1846,7 @@ module.exports = (function() {
// check if model already included, and skip if so
var model = association.target
var as = association.options.as
if (Utils._.find(includes, {daoFactory: model, as: as})) {
if (Utils._.find(includes, {model: model, as: as})) {
return
}
......@@ -1857,7 +1857,7 @@ module.exports = (function() {
// include this model
var thisInclude = optClone(include)
thisInclude.daoFactory = model
thisInclude.model = model
if (as) {
thisInclude.as = as
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!