Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let mongoose = require('mongoose')
  2. let ownerSchema = mongoose.Schema({
  3.   name: String,
  4.   cats: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Cat' }]
  5. })
  6. let Cat = require('./Cat')
  7.  
  8. ownerSchema.pre('remove', (next) => {
  9.   console.log(this)
  10.   Cat
  11.     .remove({ owner: this._id })
  12.     .exec()
  13.  
  14.   next()
  15. })
  16.  
  17. module.exports = mongoose.model('Owner', ownerSchema)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement