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

Commit 69e797e6 by Mick Hansen

feat(model): add model.removeAttribute(key), closes #1026

1 parent 5c59702a
...@@ -199,7 +199,7 @@ module.exports = (function() { ...@@ -199,7 +199,7 @@ module.exports = (function() {
for (_key in this.dataValues) { for (_key in this.dataValues) {
if (!values.hasOwnProperty(_key) && this.dataValues.hasOwnProperty(_key)) { if (!values.hasOwnProperty(_key) && this.dataValues.hasOwnProperty(_key)) {
if (options.plain && this.options.include && this.options.includeNames.indexOf(_key) !== -1) { if (options && options.plain && this.options.include && this.options.includeNames.indexOf(_key) !== -1) {
values[_key] = this.dataValues[_key].get({plain: options.plain}); values[_key] = this.dataValues[_key].get({plain: options.plain});
} else { } else {
values[_key] = this.dataValues[_key]; values[_key] = this.dataValues[_key];
......
...@@ -378,6 +378,15 @@ module.exports = (function() { ...@@ -378,6 +378,15 @@ module.exports = (function() {
}; };
/** /**
* Remove attribute from model definition
* @param {String} [attribute]
*/
Model.prototype.removeAttribute = function(attribute) {
delete this.rawAttributes[attribute];
this.refreshAttributes();
};
/**
* Sync this Model to the DB, that is create the table. Upon success, the callback will be called with the model instance (this) * Sync this Model to the DB, that is create the table. Upon success, the callback will be called with the model instance (this)
* @see {Sequelize#sync} for options * @see {Sequelize#sync} for options
* @return {Promise<this>} * @return {Promise<this>}
......
...@@ -252,6 +252,30 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -252,6 +252,30 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}) })
}) })
it('works without any primary key', function () {
var Log = this.sequelize.define('log', {
level: DataTypes.STRING
});
Log.removeAttribute('id');
return this.sequelize.sync({force: true}).then(function () {
return Promise.join(
Log.create({level: 'info'}),
Log.bulkCreate([
{level: 'error'},
{level: 'debug'}
])
);
}).then(function () {
return Log.findAll();
}).then(function (logs) {
logs.forEach(function (log) {
expect(log.get('id')).not.to.be.ok;
});
});
});
it('supports transactions', function(done) { it('supports transactions', function(done) {
var self = this; var self = this;
this.sequelize.transaction().then(function(t) { this.sequelize.transaction().then(function(t) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!