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

Commit e92577ee by Mick Hansen

Merge branch 'master' of github.com:sequelize/sequelize

Conflicts:
	changelog.md
2 parents 4244ac8d 1b54275a
# Next]
# Next
- [FIXED] Model.aggregate methods now support attributes and where conditions with fields. [#4935](https://github.com/sequelize/sequelize/issues/4935)
- [FIXED] Don't overwrite options.foreignKey in associations [#4927](https://github.com/sequelize/sequelize/pull/4927)
# 3.14.1
- [FIXED] Issue with transaction options leaking and certain queries running outside of the transaction connection.
......
......@@ -53,7 +53,8 @@ sequelize
.authenticate()
.then(function(err) {
console.log('Connection has been established successfully.');
}, function (err) {
})
.catch(function (err) {
console.log('Unable to connect to the database:', err);
});
```
......
......@@ -510,12 +510,12 @@ Project.create({ /* */ }).then(function(project) {
// check if all associated objects are as expected:
// let's assume we have already a project and two users
project.setUsers([user1, user2]).then(function() {
return project.hasUsers([user1]).then(function(result) {
// result would be false
return project.hasUsers([user1, user2]).then(function(result) {
// result would be true
})
})
return project.hasUsers([user1]);
}).then(function(result) {
// result would be false
return project.hasUsers([user1, user2]);
}).then(function(result) {
// result would be true
})
```
......
......@@ -113,10 +113,9 @@ Once you created an object and got a reference to it, you can delete it fr
```js
Task.create({ title: 'a task' }).then(function(task) {
// now you see me...
 
task.destroy().then(function() {
// now i'm gone :)
})
return task.destroy();
}).then(function() {
 // now i'm gone :)
})
```
......@@ -144,9 +143,9 @@ User.bulkCreate([
{ username: 'foo', isAdmin: true },
{ username: 'bar', isAdmin: false }
]).then(function() { // Notice: There are no arguments here, as of right now you'll have to...
User.findAll().then(function(users) {
console.log(users) // ... in order to get the array of user objects
})
return User.findAll();
}).then(function(users) {
console.log(users) // ... in order to get the array of user objects
})
```
......@@ -158,15 +157,15 @@ Task.bulkCreate([
{subject: 'reading', status: 'executing'},
{subject: 'programming', status: 'finished'}
]).then(function() {
Task.update(
{ status: 'inactive' } /* set attributes' value */,
return Task.update(
{ status: 'inactive' }, /* set attributes' value */,
{ where: { subject: 'programming' }} /* where criteria */
).then(function(affectedRows) {
// affectedRows will be 2
Task.findAll().then(function(tasks) {
console.log(tasks) // the 'programming' tasks will both have a status of 'inactive'
})
})
);
}).then(function(affectedRows) {
// affectedRows will be 2
return Task.findAll();
}).then(function(tasks) {
console.log(tasks) // the 'programming' tasks will both have a status of 'inactive'
})
```
......@@ -178,17 +177,17 @@ Task.bulkCreate([
{subject: 'reading', status: 'executing'},
{subject: 'programming', status: 'finished'}
]).then(function() {
Task.destroy({
return Task.destroy({
where: {
subject: 'programming'
},
truncate: true /* this will ignore where and truncate the table instead */
}).then(function(affectedRows) {
// affectedRows will be 2
Task.findAll().then(function(tasks) {
console.log(tasks) // no programming, just reading :(
})
})
});
}).then(function(affectedRows) {
// affectedRows will be 2
return Task.findAll();
}).then(function(tasks) {
console.log(tasks) // no programming, just reading :(
})
```
......@@ -294,27 +293,27 @@ First of all you can define a field and the value you want to add to it.
```js
User.findById(1).then(function(user) {
user.increment('my-integer-field', {by: 2}).then(/* ... */)
})
return user.increment('my-integer-field', {by: 2})
}).then(/* ... */)
```
Second, you can define multiple fields and the value you want to add to them.
```js
User.findById(1).then(function(user) {
user.increment([ 'my-integer-field', 'my-very-other-field' ], {by: 2}).then(/* ... */)
})
return user.increment([ 'my-integer-field', 'my-very-other-field' ], {by: 2})
}).then(/* ... */)
```
Third, you can define an object containing fields and its increment values.
```js
User.findById(1).then(function(user) {
user.increment({
return user.increment({
'my-integer-field': 2,
'my-very-other-field': 3
}).then(/* ... */)
})
})
}).then(/* ... */)
```
## Decrementing certain values of an instance
......@@ -325,25 +324,25 @@ First of all you can define a field and the value you want to add to it.
```js
User.findById(1).then(function(user) {
user.decrement('my-integer-field', {by: 2}).then(/* ... */)
})
return user.decrement('my-integer-field', {by: 2})
}).then(/* ... */)
```
Second, you can define multiple fields and the value you want to add to them.
```js
User.findById(1).then(function(user) {
user.decrement([ 'my-integer-field', 'my-very-other-field' ], {by: 2}).then(/* ... */)
})
return user.decrement([ 'my-integer-field', 'my-very-other-field' ], {by: 2})
}).then(/* ... */)
```
Third, you can define an object containing fields and its decrement values.
```js
User.findById(1).then(function(user) {
user.decrement({
return user.decrement({
'my-integer-field': 2,
'my-very-other-field': 3
}).then(/* ... */)
})
})
}).then(/* ... */)
```
......@@ -146,7 +146,7 @@ $col: 'user.organization_id' // = "user"."organization_id", with dialect specifi
{
rank: {
$or: {
$lt: 100,
$lt: 1000,
$eq: null
}
}
......
......@@ -24,10 +24,10 @@ sequelize.sync().then(function() {
return User.create({
username: 'janedoe',
birthday: new Date(1980, 6, 20)
}).then(function(jane) {
console.log(jane.get({
plain: true
}))
});
});
}).then(function(jane) {
console.log(jane.get({
plain: true
}));
});
```
......@@ -323,8 +323,8 @@ BelongsToMany.prototype.injectAttributes = function() {
, targetKey = this.target.rawAttributes[this.target.primaryKeyAttribute]
, targetKeyType = targetKey.type
, targetKeyField = targetKey.field || this.target.primaryKeyAttribute
, sourceAttribute = _.defaults(this.foreignKeyAttribute, { type: sourceKeyType })
, targetAttribute = _.defaults(this.otherKeyAttribute, { type: targetKeyType });
, sourceAttribute = _.defaults({}, this.foreignKeyAttribute, { type: sourceKeyType })
, targetAttribute = _.defaults({}, this.otherKeyAttribute, { type: targetKeyType });
if (this.primaryKeyDeleted === true) {
targetAttribute.primaryKey = sourceAttribute.primaryKey = true;
......
......@@ -109,7 +109,7 @@ util.inherits(BelongsTo, Association);
BelongsTo.prototype.injectAttributes = function() {
var newAttributes = {};
newAttributes[this.foreignKey] = _.defaults(this.foreignKeyAttribute, {
newAttributes[this.foreignKey] = _.defaults({}, this.foreignKeyAttribute, {
type: this.options.keyType || this.target.rawAttributes[this.targetKey].type,
allowNull : true
});
......
......@@ -202,7 +202,7 @@ util.inherits(HasMany, Association);
HasMany.prototype.injectAttributes = function() {
var newAttributes = {};
var constraintOptions = _.clone(this.options); // Create a new options object for use with addForeignKeyConstraints, to avoid polluting this.options in case it is later used for a n:m
newAttributes[this.foreignKey] = _.defaults(this.foreignKeyAttribute, {
newAttributes[this.foreignKey] = _.defaults({}, this.foreignKeyAttribute, {
type: this.options.keyType || this.source.rawAttributes[this.source.primaryKeyAttribute].type,
allowNull : true
});
......
......@@ -103,7 +103,7 @@ HasOne.prototype.injectAttributes = function() {
var newAttributes = {}
, keyType = this.source.rawAttributes[this.source.primaryKeyAttribute].type;
newAttributes[this.foreignKey] = _.defaults(this.foreignKeyAttribute, {
newAttributes[this.foreignKey] = _.defaults({}, this.foreignKeyAttribute, {
type: this.options.keyType || keyType,
allowNull : true
});
......
......@@ -97,6 +97,7 @@ ConnectionManager.prototype.initPools = function () {
},
destroy: function(connection) {
self.$disconnect(connection);
return null;
},
max: config.pool.max,
min: config.pool.min,
......@@ -174,6 +175,7 @@ ConnectionManager.prototype.initPools = function () {
},
destroy: function(connection) {
self.$disconnect(connection);
return null;
},
validate: config.pool.validate,
max: config.pool.max,
......@@ -191,6 +193,7 @@ ConnectionManager.prototype.initPools = function () {
},
destroy: function(connection) {
self.$disconnect(connection);
return null;
},
validate: config.pool.validate,
max: config.pool.max,
......@@ -221,6 +224,7 @@ ConnectionManager.prototype.getConnection = function(options) {
self.versionPromise = null;
self.$disconnect(connection);
return null;
});
}).catch(function (err) {
self.versionPromise = null;
......
......@@ -2450,6 +2450,7 @@ Model.prototype.update = function(values, options) {
delete options.attributes;
});
}
return null;
}).then(function() {
valuesUse = values;
......
'use strict';
/* jshint -W030 */
var chai = require('chai')
, expect = chai.expect
, Support = require(__dirname + '/../support')
, DataTypes = require(__dirname + '/../../../lib/data-types')
, Sequelize = require('../../../index');
describe(Support.getTestDialectTeaser('associations'), function() {
describe('Test options.foreignKey', function() {
beforeEach(function() {
this.A = this.sequelize.define('A', {
id: {
type: DataTypes.CHAR(20),
primaryKey: true
}
});
this.B = this.sequelize.define('B', {
id: {
type: Sequelize.CHAR(20),
primaryKey: true
}
});
this.C = this.sequelize.define('C', {});
});
it('should not be overwritten for belongsTo', function(){
var reqValidForeignKey = { foreignKey: { allowNull: false }};
this.A.belongsTo(this.B, reqValidForeignKey);
this.A.belongsTo(this.C, reqValidForeignKey);
expect(this.A.attributes.CId.type).to.deep.equal(this.C.attributes.id.type);
});
it('should not be overwritten for belongsToMany', function(){
var reqValidForeignKey = { foreignKey: { allowNull: false }, through: 'ABBridge'};
this.B.belongsToMany(this.A, reqValidForeignKey);
this.A.belongsTo(this.C, reqValidForeignKey);
expect(this.A.attributes.CId.type).to.deep.equal(this.C.attributes.id.type);
});
it('should not be overwritten for hasOne', function(){
var reqValidForeignKey = { foreignKey: { allowNull: false }};
this.B.hasOne(this.A, reqValidForeignKey);
this.A.belongsTo(this.C, reqValidForeignKey);
expect(this.A.attributes.CId.type).to.deep.equal(this.C.attributes.id.type);
});
it('should not be overwritten for hasMany', function(){
var reqValidForeignKey = { foreignKey: { allowNull: false }};
this.B.hasMany(this.A, reqValidForeignKey);
this.A.belongsTo(this.C, reqValidForeignKey);
expect(this.A.attributes.CId.type).to.deep.equal(this.C.attributes.id.type);
});
});
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!