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

Commit a3dc4bef by Mick Hansen

fix(model): model#destroy now supports field, this also fixes an issue with N:M#…

…removeAssociation and field
1 parent 34eb02e7
# Next
- [BUG] Add support for `field` named the same as the attribute in `reload`, `bulkCreate` and `save` [#2348](https://github.com/sequelize/sequelize/issues/2348)
- [BUG] Copy the options object in association getters. [#2311](https://github.com/sequelize/sequelize/issues/2311)
- [BUG] `Model#destroy()` now supports `field`, this also fixes an issue with `N:M#removeAssociation` and `field`
#### Backwards compatability changes
- When eager-loading a many-to-many association, the attributes of the through table are now accessible through an attribute named after the through model rather than the through table name singularized. i.e. `Task.find({include: Worker})` where the table name for through model `TaskWorker` is `TableTaskWorkers` used to produce `{ Worker: { ..., TableTaskWorker: {...} } }`. It now produces `{ Worker: { ..., TaskWorker: {...} } }`. Does not affect models where table name is auto-defined by Sequelize, or where table name is model name pluralized.
......
......@@ -1344,6 +1344,8 @@ module.exports = (function() {
var self = this
, instances;
mapFieldNames.call(this, options, this);
return Promise.try(function() {
// Run before hook
if (options.hooks) {
......
......@@ -1582,8 +1582,9 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
var project = projects[0];
expect(project).to.be.defined;
return self.user.removeProject(project);
}).then(function() {
return self.user.removeProject(project).on('sql', function (sql) {
}).return(project);
}).then(function(project) {
return self.user.setProjects([project]);
});
});
......
......@@ -1048,6 +1048,31 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
it('supports .field', function () {
var UserProject = this.sequelize.define('UserProject', {
userId: {
type: DataTypes.INTEGER,
field: 'user_id'
}
});
return UserProject.sync({force: true}).then(function () {
return UserProject.create({
userId: 10
});
}).then(function (userProject) {
return UserProject.destroy({
where: {
userId: 10
}
});
}).then(function () {
return UserProject.findAll();
}).then(function (userProjects) {
expect(userProjects.length).to.equal(0);
});
});
it('sets deletedAt to the current timestamp if paranoid is true', function(done) {
var self = this
, ParanoidUser = self.sequelize.define('ParanoidUser', {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!