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