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

Commit ee4dde20 by Mick Hansen

Merge branch 'master' into milestones/2.0.0

2 parents d801f426 79b1f6f4
Notice: All 1.7.x changes are present in 2.0.x aswell Notice: All 1.7.x changes are present in 2.0.x aswell
# v1.7.0-rc9 # v1.7.0-rc9 (next)
- [PERFORMANCE] fixes performance regression introduced in rc7 - [PERFORMANCE] fixes performance regression introduced in rc7
- [FEATURE] include all relations for a model [#1421](https://github.com/sequelize/sequelize/pull/1421) - [FEATURE] include all relations for a model [#1421](https://github.com/sequelize/sequelize/pull/1421)
- [FEATURE] covers more advanced include cases with limiting and filtering
# v1.7.0-rc8 # v1.7.0-rc8
- [BUG] fixes bug with required includes without wheres with subqueries - [BUG] fixes bug with required includes without wheres with subqueries
......
...@@ -25,16 +25,12 @@ module.exports = (function() { ...@@ -25,16 +25,12 @@ module.exports = (function() {
//fully qualify //fully qualify
var instancePrimaryKeys = Object.keys(self.instance.Model.primaryKeys) var instancePrimaryKeys = Object.keys(self.instance.Model.primaryKeys)
, instancePrimaryKey = instancePrimaryKeys.length > 0 ? instancePrimaryKeys[0] : 'id' , instancePrimaryKey = instancePrimaryKeys.length > 0 ? instancePrimaryKeys[0] : 'id'
where[through.tableName+"."+self.association.identifier] = self.instance[instancePrimaryKey]
var primaryKeys = Object.keys(through.primaryKeys)
, foreignKey = primaryKeys.filter(function(pk) { return pk != self.association.identifier })[0]
, foreignPrimary = Object.keys(self.association.target.primaryKeys) , foreignPrimary = Object.keys(self.association.target.primaryKeys)
foreignPrimary = foreignPrimary.length === 1 ? foreignPrimary[0] : 'id' foreignPrimary = foreignPrimary.length === 1 ? foreignPrimary[0] : 'id'
where[through.tableName+"."+foreignKey] = {join: self.association.target.tableName+"."+foreignPrimary} where[through.tableName+"."+self.association.identifier] = self.instance[instancePrimaryKey]
where[through.tableName+"."+self.association.foreignIdentifier] = {join: self.association.target.tableName+"."+foreignPrimary}
if (Object(targetAssociation.through) === targetAssociation.through) { if (Object(targetAssociation.through) === targetAssociation.through) {
queryOptions.hasJoinTableModel = true queryOptions.hasJoinTableModel = true
......
...@@ -946,7 +946,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() { ...@@ -946,7 +946,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
}) })
}) })
describe('join table model', function () { describe('through', function () {
beforeEach(function (done) { beforeEach(function (done) {
this.User = this.sequelize.define('User', {}) this.User = this.sequelize.define('User', {})
this.Project = this.sequelize.define('Project', {}) this.Project = this.sequelize.define('Project', {})
...@@ -1049,9 +1049,56 @@ describe(Support.getTestDialectTeaser("HasMany"), function() { ...@@ -1049,9 +1049,56 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
this.sequelize.sync().done(function(err) { this.sequelize.sync().done(function(err) {
expect(err).not.to.be.ok expect(err).not.to.be.ok
Worker.create().done(function (err, worker) { Worker.create({id: 1337}).done(function (err, worker) {
expect(err).not.to.be.ok
Task.create({id: 7331}).done(function (err, task) {
expect(err).not.to.be.ok
worker.addTask(task).done(function (err) {
expect(err).not.to.be.ok
worker.addTask(task).done(function (err) {
expect(err).not.to.be.ok
done()
})
})
})
})
})
})
it('should be able to add twice (second call result in UPDATE call) with custom primary keys and without any attributes (and timestamps off) on the through model', function (done) {
var Worker = this.sequelize.define('Worker', {
id: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true
}
}, {timestamps: false})
, Task = this.sequelize.define('Task', {
id: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true
}
}, {timestamps: false})
, WorkerTasks = this.sequelize.define('WorkerTasks', {
id: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true
}
}, {timestamps: false})
Worker.hasMany(Task, { through: WorkerTasks })
Task.hasMany(Worker, { through: WorkerTasks })
this.sequelize.sync().done(function(err) {
expect(err).not.to.be.ok
Worker.create({id: 1337}).done(function (err, worker) {
expect(err).not.to.be.ok expect(err).not.to.be.ok
Task.create().done(function (err, task) { Task.create({id: 7331}).done(function (err, task) {
expect(err).not.to.be.ok expect(err).not.to.be.ok
worker.addTask(task).done(function (err) { worker.addTask(task).done(function (err) {
expect(err).not.to.be.ok expect(err).not.to.be.ok
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!