meteor-collection-behaviours
meteor-collection-behaviours copied to clipboard
softRemovable not in place when creating new user
Applying behaviours to the Meteor.users collection is working fine like this:
CollectionBehaviours.extendCollectionInstance(Meteor.users);
Meteor.users.softRemovable();
When I delete a user, the document remains in the database, but is not returned from Meteor.users.find() – great! The problem arises when the user tries to create a new account with the same e-mail. Meteor says that a user already exists with that e-mail.
Anything I/we can do about this? Thanks.
I've solved this by redefining the softRemovable behaviour. It's only a small change. In the new version, when applying the behaviour, a modifier object can be passed as an argument.
The new modifier (defaulted to an empty object) is then extended (using _.default) with the base modifier used inside the .before.update hook, which would normally just $set removed and removedAt. The new modifier is used in place of the base modifier in the update operation.
In regard to the Meteor.users collection, I pass the object below as the new modifier – this way, when creating new users in the future, the duplicate check comes out negative.
Meteor.users.softRemovable({
$rename: {
"emails": "removedEmails",
"services": "removedServices"
}
});
http://atmospherejs.com/zimme/collection-softremovable