brainlet/models/Channel.js

19 lines
No EOL
489 B
JavaScript
Executable file

const mongoose = require("mongoose");
const User = require("./User");
const channelSchema = new mongoose.Schema({
title: String,
creator: {type: mongoose.Schema.Types.ObjectId, ref: "User"}
});
channelSchema.method("getPublicObject", function() {
return {
title: this.title,
creator: this.populate("creator", User.getPulicFields()).creator,
_id: this._id
};
});
const Channel = mongoose.model("Channel", channelSchema);
module.exports = Channel;