+PodSchema.pre('save', function (next) {
+ const self = this
+
+ Pod.loadByUrl(this.url, function (err, pod) {
+ if (err) return next(err)
+
+ if (pod) return next(new Error('Pod already exists.'))
+
+ self.score = constants.FRIEND_SCORE.BASE
+ return next()
+ })
+})
+
+PodSchema.pre('remove', function (next) {
+ // Remove the videos owned by this pod too
+ Video.listByUrl(this.url, function (err, videos) {
+ if (err) return next(err)
+
+ each(videos, function (video, callbackEach) {
+ video.remove(callbackEach)
+ }, next)
+ })
+})