diff options
Diffstat (limited to 'server/models/pods.js')
-rw-r--r-- | server/models/pods.js | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/server/models/pods.js b/server/models/pods.js index 4020a9603..6ab018c1c 100644 --- a/server/models/pods.js +++ b/server/models/pods.js | |||
@@ -1,11 +1,14 @@ | |||
1 | 'use strict' | 1 | 'use strict' |
2 | 2 | ||
3 | const each = require('async/each') | ||
3 | const mongoose = require('mongoose') | 4 | const mongoose = require('mongoose') |
4 | const map = require('lodash/map') | 5 | const map = require('lodash/map') |
5 | const validator = require('express-validator').validator | 6 | const validator = require('express-validator').validator |
6 | 7 | ||
7 | const constants = require('../initializers/constants') | 8 | const constants = require('../initializers/constants') |
8 | 9 | ||
10 | const Video = mongoose.model('Video') | ||
11 | |||
9 | // --------------------------------------------------------------------------- | 12 | // --------------------------------------------------------------------------- |
10 | 13 | ||
11 | const PodSchema = mongoose.Schema({ | 14 | const PodSchema = mongoose.Schema({ |
@@ -51,6 +54,17 @@ PodSchema.pre('save', function (next) { | |||
51 | }) | 54 | }) |
52 | }) | 55 | }) |
53 | 56 | ||
57 | PodSchema.pre('remove', function (next) { | ||
58 | // Remove the videos owned by this pod too | ||
59 | Video.listByUrl(this.url, function (err, videos) { | ||
60 | if (err) return next(err) | ||
61 | |||
62 | each(videos, function (video, callbackEach) { | ||
63 | video.remove(callbackEach) | ||
64 | }, next) | ||
65 | }) | ||
66 | }) | ||
67 | |||
54 | const Pod = mongoose.model('Pod', PodSchema) | 68 | const Pod = mongoose.model('Pod', PodSchema) |
55 | 69 | ||
56 | // ------------------------------ METHODS ------------------------------ | 70 | // ------------------------------ METHODS ------------------------------ |