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

Commit 22d24b8f by Ryan Pon

improve paranoid=false docs, test paranoid=false with include

1 parent 7f92646d
Showing with 49 additions and 7 deletions
...@@ -629,7 +629,7 @@ module.exports = (function() { ...@@ -629,7 +629,7 @@ module.exports = (function() {
* @param {Object} [options] A hash of options to describe the scope of the search * @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 {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 {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 {Boolean} [options.paranoid=true] 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 {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 {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 * @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
......
...@@ -965,21 +965,21 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -965,21 +965,21 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}, { paranoid: true }) }, { paranoid: true })
return User.sync({ force: true }) return User.sync({ force: true })
.success(function() { .then(function() {
return User.bulkCreate([ return User.bulkCreate([
{username: 'Toni'}, {username: 'Toni'},
{username: 'Tobi'}, {username: 'Tobi'},
{username: 'Max'} {username: 'Max'}
]); ]);
}) })
.success(function() { return User.find(1) }) .then(function() { return User.find(1) })
.success(function(user) { return user.destroy() }) .then(function(user) { return user.destroy() })
.success(function() { return User.find({ where: 1, paranoid: false }) }) .then(function() { return User.find({ where: 1, paranoid: false }) })
.success(function(user) { .then(function(user) {
expect(user).to.exist expect(user).to.exist
return User.find(1) return User.find(1)
}) })
.success(function(user) { .then(function(user) {
expect(user).to.be.null expect(user).to.be.null
return [User.count(), User.count({ paranoid: false })] return [User.count(), User.count({ paranoid: false })]
}) })
...@@ -990,6 +990,48 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -990,6 +990,48 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}) })
}) })
it('should include deleted associated records if include has paranoid marked as false', function() {
var User = this.sequelize.define('User', {
username: Sequelize.STRING
}, { paranoid: true })
var Pet = this.sequelize.define('Pet', {
name: Sequelize.STRING,
UserId: Sequelize.INTEGER
}, { paranoid: true })
User.hasMany(Pet)
Pet.belongsTo(User)
var user;
return User.sync({ force: true })
.then(function() { return Pet.sync({ force: true }) })
.then(function() { return User.create({ username: 'Joe' }) })
.then(function(_user) {
user = _user;
return Pet.bulkCreate([
{ name: 'Fido', UserId: user.id },
{ name: 'Fifi', UserId: user.id }
]);
})
.then(function () { return Pet.find(1) })
.then(function (pet) { return pet.destroy() })
.then(function () {
return [
User.find({ where: user.id, include: Pet }),
User.find({
where: user.id,
include: [{ model: Pet, paranoid: false }]
})
]
})
.spread(function (user, userWithDeletedPets) {
expect(user).to.exist
expect(user.Pets).to.have.length(1)
expect(userWithDeletedPets).to.exist
expect(userWithDeletedPets.Pets).to.have.length(2)
})
})
it('should delete a paranoid record if I set force to true', function(done) { it('should delete a paranoid record if I set force to true', function(done) {
var self = this var self = this
var User = this.sequelize.define('paranoiduser', { 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!