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

Commit 7f92646d by Ryan Pon

add flag to retreive deleted paranoid models in queries

1 parent 2bb1845c
Showing with 34 additions and 1 deletions
......@@ -629,6 +629,7 @@ module.exports = (function() {
* @param {Object} [options] A hash of options to describe the scope of the search
* @param {Object} [options.where] A hash of attributes to describe your search. See above for examples.
* @param {Array<String>} [options.attributes] A list of the attributes that you want to select. To rename an attribute, you can pass an array, with two elements - the first is the name of the attribute in the DB (or some kind of expression such as `Sequelize.literal`, `Sequelize.fn` and so on), and the second is the name you want the attribute to have in the returned instance
* @param {Boolean} [options.paranoid] If false, will include columns which have a non-null deletedAt column.
* @param {Array<Object|Model>} [options.include] A list of associations to eagerly load using a left join. Supported is either `{ include: [ Model1, Model2, ...]}` or `{ include: [{ model: Model1, as: 'Alias' }]}`. If your association are set up with an `as` (eg. `X.hasMany(Y, { as: 'Z }`, you need to specify Z in the as attribute when eager loading Y).
* @param {Model} [options.include[].model] The model you want to eagerly load
* @param {String} [options.include[].as] The alias of the relation, in case the model you want to eagerly load is aliassed. For `hasOne` / `belongsTo`, this should be the singular name, and for `hasMany`, it should be the plural
......@@ -1547,7 +1548,7 @@ module.exports = (function() {
// private
var paranoidClause = function(options ) {
if (! this.options.timestamps || ! this.options.paranoid) return options || {};
if (! this.options.timestamps || ! this.options.paranoid || options.paranoid === false) return options || {};
options = options || {};
options.where = options.where || {};
......
......@@ -958,6 +958,38 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
describe('can find paranoid records if paranoid is marked as false in query', function() {
it('with the DAOFactory', function() {
var User = this.sequelize.define('UserCol', {
username: Sequelize.STRING
}, { paranoid: true })
return User.sync({ force: true })
.success(function() {
return User.bulkCreate([
{username: 'Toni'},
{username: 'Tobi'},
{username: 'Max'}
]);
})
.success(function() { return User.find(1) })
.success(function(user) { return user.destroy() })
.success(function() { return User.find({ where: 1, paranoid: false }) })
.success(function(user) {
expect(user).to.exist
return User.find(1)
})
.success(function(user) {
expect(user).to.be.null
return [User.count(), User.count({ paranoid: false })]
})
.spread(function(cnt, cntWithDeleted) {
expect(cnt).to.equal(2)
expect(cntWithDeleted).to.equal(3)
})
})
})
it('should delete a paranoid record if I set force to true', function(done) {
var self = this
var User = this.sequelize.define('paranoiduser', {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!