These are chat archives for Automattic/mongoose

8th
Jul 2016
Yogesh Patel
@ycpatel813
Jul 08 2016 08:07
@matiasgaratortiz platforms is array so you have to use map or something or you have to use platforms[0].name
Patrick Kranzlmueller
@sehmaschine
Jul 08 2016 15:09
I'm struggling with saving related objects using pre ... here's my code ...
var SectionSchema = new Schema({
    name: { type: String, maxlength: 100, required: true, unique: true },
    entries: [{ type: Schema.Types.ObjectId, ref: 'Entry' }]
})
SectionSchema.pre('save', function(next) {
    this.entries = Entry.find({'section': this._id}, function (err, results) {
        // ??? what exactly do I need to return here ???
    })
    next()
})
For the sake of completeness, the EntrySchema ...
var EntrySchema = new Schema({
    title: { type: String, maxlength: 200, required: true },
    section: { type: Schema.Types.ObjectId, ref: 'Section', required: true },
})