I have 2 models.
Model 1:
const userSchema = new mongoose.Schema({
email: { type: String, unique: true, required: true },
password: { type: String, required: true },
passwordResetToken: String,
passwordResetExpires: Date,
facebook: String,
twitter: String,
tokens: Array,
profile: {
name: String,
gender: String,
location: String,
website: String,
picture: String
}
}, { timestamps: true });
Model 2:
const reviveSchema = new mongoose.Schema({
reviveShowName: {type: String, required: true},
reviveTitle: {type: String, required: true},
reviveCategory: {type: String, required: true},
reviveGoal: {type: Number, required: true},
revivePhoto: {type: String, required: true},
reviveVideo: {type: String},
reviveStory: {type: String},
author: {
id: {
type: mongoose.Schema.Types.ObjectId,
ref: "User"
}
}
}, { timestamps: true });
How can I pass the author's name to the show view of a particular revive?
This is how I was getting to the show view before I realized that I needed the author's data to be passed to the view as well:
exports.showRevive = (req, res, next) => {
Revive.findById(req.params.id, (err, foundRevive) => {
if(err) {
console.log(err);
} else {
res.render('revive/show_revive', {revive: foundRevive});
}
});
};
That works just fine but then to get the author's data in the revive show view as well I tried this:
exports.showRevive = (req, res, next) => {
Revive.findById(req.params.id)
.populate('author')
.exec(function(err, foundRevive) {
if(err) {
console.log(err);
} else {
res.render('revive/show_revive', {revive: foundRevive});
}
});
};
That did not work... Can you guys please point me in the right direction? Thanks!