I have an Assignment schema
which has references to Groups
and Projects
.
Assignment == Group [One-One Relationship]
A
In the remove
middleware, you're defining the actions to take when a document of the model for that schema is removed via Model#remove. So:
group
reference to that group's _id
from all assignment docs.projects
array element references to that project's _id
from all assignment docs.Which you can implement as:
GroupSchema.pre('remove', function(next) {
var group = this;
group.model('Assignment').update(
{ group: group._id },
{ $unset: { group: 1 } },
{ multi: true },
next);
});
ProjectSchema.pre('remove', function (next) {
var project = this;
project.model('Assignment').update(
{ projects: project._id },
{ $pull: { projects: project._id } },
{ multi: true },
next);
});