I've seen many examples about mongoose and relations, but how can I create a reference to another entity into a custom field ?
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');
mongoose.connection.once('open', function(){
var Author = m.model('Author', new m.Schema({
name: String,
slugname: String
}));
var Book = m.model('Book', new m.Schema({
title: String,
author: {type: String, ref: 'Author.slugname'}
}));
});
In the code above, I'm linking Book.author into Author.slugname. it is just that I don't if this is the right way to do it.