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

Commit 10ec7ff6 by Martin Aspeli

Tidy up setting of new attributes

1 parent 559e1cef
......@@ -24,12 +24,14 @@ module.exports = (function() {
this.identifier = this.options.foreignKey || Utils._.underscoredIf(Utils.singularize(this.target.tableName) + "Id", this.source.options.underscored)
newAttributes[this.identifier] = { type: DataTypes.INTEGER }
if(typeof this.options.foreignKey === "undefined" || this.options.foreignKey === true) {
if(this.options.foreignKeyConstraint || this.options.onDelete || this.options.onUpdate) {
newAttributes[this.identifier].references = this.target.tableName,
newAttributes[this.identifier].referencesKeys = Utils._.reduce(this.source.rawAttributes, function(memo, value, key) { if(value.primaryKey) { memo.push(key) } return memo }, [])
newAttributes[this.identifier].referencesKeys = Utils._.filter(Utils._.keys(this.target.rawAttributes), function(key) { return this.target.rawAttributes[key].primaryKey }, this)
newAttributes[this.identifier].onDelete = this.options.onDelete,
newAttributes[this.identifier].onUpdate = this.options.onUpdate
}
Utils._.defaults(this.source.rawAttributes, newAttributes)
// Sync attributes to DAO proto each time a new assoc is added
......
......@@ -65,12 +65,14 @@ module.exports = (function() {
} else {
var newAttributes = {}
newAttributes[this.identifier] = { type: DataTypes.INTEGER }
if(typeof this.options.foreignKey === "undefined" || this.options.foreignKey === true) {
if(this.options.foreignKeyConstraint || this.options.onDelete || this.options.onUpdate) {
newAttributes[this.identifier].references = this.source.tableName
newAttributes[this.identifier].referencesKeys = Utils._.reduce(this.source.rawAttributes, function(memo, value, key) { if(value.primaryKey) { memo.push(key) } return memo }, [])
newAttributes[this.identifier].referencesKeys = Utils._.filter(Utils._.keys(this.source.rawAttributes), function(key) { return this.source.rawAttributes[key].primaryKey }, this)
newAttributes[this.identifier].onDelete = this.options.onDelete
newAttributes[this.identifier].onUpdate = this.options.onUpdate
}
Utils._.defaults(this.target.rawAttributes, newAttributes)
}
......
......@@ -29,12 +29,14 @@ module.exports = (function() {
this.identifier = this.options.foreignKey || Utils._.underscoredIf(Utils.singularize(this.source.tableName) + "Id", this.options.underscored)
newAttributes[this.identifier] = { type: DataTypes.INTEGER }
if(typeof this.options.foreignKey === "undefined" || this.options.foreignKey === true) {
if(this.options.foreignKeyConstraint || this.options.onDelete || this.options.onUpdate) {
newAttributes[this.identifier].references = this.source.tableName,
newAttributes[this.identifier].referencesKeys = Utils._.reduce(this.source.rawAttributes, function(memo, value, key) { if(value.primaryKey) { memo.push(key) } return memo }, [])
newAttributes[this.identifier].referencesKeys = Utils._.filter(Utils._.keys(this.source.rawAttributes), function(key) { return this.source.rawAttributes[key].primaryKey }, this)
newAttributes[this.identifier].onDelete = this.options.onDelete,
newAttributes[this.identifier].onUpdate = this.options.onUpdate
}
Utils._.defaults(this.target.rawAttributes, newAttributes)
// Sync attributes to DAO proto each time a new assoc is added
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!