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

Commit 1f89402e by Sascha Depold

some convenience stuff

1 parent 803192aa
var Utils = require("./../utils")
, DataTypes = require('./../data-types')
, QueryChainer = require("./../query-chainer")
var HasMany = module.exports = function(srcModel, targetModel, options) {
this.source = srcModel
......@@ -78,7 +77,7 @@ HasMany.prototype.injectSetter = function(obj) {
instance[self.accessors.get]().on('success', function(oldAssociatedObjects) {
if(self.connectorModel) {
var foreignIdentifier = self.target.associations[self.source.tableName].identifier
var destroyChainer = new QueryChainer
var destroyChainer = new Utils.QueryChainer
// destroy the old association objects
oldAssociatedObjects.forEach(function(associatedObject) { destroyChainer.add(associatedObject.destroy()) })
destroyChainer
......@@ -87,7 +86,7 @@ HasMany.prototype.injectSetter = function(obj) {
.on('success', function() {
// create new one
var createChainer = new QueryChainer
var createChainer = new Utils.QueryChainer
newAssociatedObjects.forEach(function(associatedObject) {
var attributes = {}
attributes[self.identifier] = instance.id
......@@ -110,7 +109,7 @@ HasMany.prototype.injectSetter = function(obj) {
})
// set the new one
var chainer = new QueryChainer
var chainer = new Utils.QueryChainer
newAssociatedObjects.forEach(function(associatedObject) {
associatedObject[self.identifier] = instance.id
chainer.add(associatedObject.save())
......
......@@ -19,6 +19,7 @@ var Sequelize = module.exports = function(database, username, password, options)
port : options.port || 3306
}
}
Sequelize.Utils = Utils
var instanceMethods = {
define: function(modelName, attributes, options) {
......@@ -37,5 +38,5 @@ var instanceMethods = {
}
Utils._.map(require('./data-types'), function(sql, accessor) { Sequelize[accessor] = sql})
Utils._.map(instanceMethods, function(fct, name) { Sequelize.prototype[name] = fct})
\ No newline at end of file
Sequelize.Utils._.map(require('./data-types'), function(sql, accessor) { Sequelize[accessor] = sql})
Sequelize.Utils._.map(instanceMethods, function(fct, name) { Sequelize.prototype[name] = fct})
\ No newline at end of file
......@@ -128,6 +128,7 @@ var Utils = module.exports = {
}
}
// Some nice class accessors
var CustomEventEmitter = Utils.CustomEventEmitter = function(fct) {
this.fct = fct
}
......@@ -137,4 +138,6 @@ CustomEventEmitter.prototype.run = function() {
var self = this
setTimeout(function(){ self.fct() }, 5) // delay the function call and return the emitter
return this
}
\ No newline at end of file
}
Utils.QueryChainer = require("./query-chainer")
\ No newline at end of file
......@@ -2,7 +2,7 @@ var assert = require("assert")
, config = require("./../config")
, Sequelize = require("./../../index")
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false})
module.exports = {
'it should correctly add the foreign id': function() {
var num = parseInt(Math.random() * 99999999)
......
module.exports = {
username: 'root',
password: null,
database: 'sequelize_test'
database: 'sequelize_test',
host: '127.0.0.1'
}
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!