New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add flag to retreive deleted paranoid models in queries #2083
Conversation
I'm pretty sure your implementation already supports it, but could you add a test to ensure that it works for includes as well? |
@@ -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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember to add default value (=true). Perhaps is should also just say "both existing and deleted records"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's slightly misleading since the default is undefined and it's comparing against false
to see if they set the flag. Still ok to do default as true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ryanpon the behaviour is still as if it was true. So for the sake of the user it's best to tell them that this is turned on by default :)
Something like Model.find({
include: [
{model: RelatedModel, paranoid: false }
]
}); Should only return model instances that are not deleted, but all related instances of relatedModel, both deleted and not |
Sure, I'll add the tests for includes as well. |
{username: 'Max'} | ||
]); | ||
}) | ||
.success(function() { return User.find(1) }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you change all these success
to then
?
then
is the correct method, success
is just our BC method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to know. I use Q promises normally, and I assumed that .success was just part of the bluebird api.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope :) .success is just a backwards compat remnant from the event emitter pattern that we switched away from here on 2.0/master
Added and revised tests, added the default value as requested. |
Beautiful. Thank you. |
Add flag to retreive deleted paranoid models in queries
@brunocasanova take a peek at this! |
Implementation as suggested in #1862