This repository was archived by the owner on Jul 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Model Ambiguity? #13
Copy link
Copy link
Open
Description
Maybe I'm missing something, however what happens if a Schema has two fields of the same model? For example, taking the example from the main site, let's say we also want to keep track of an editor.
var mongoose = require('mongoose');
require('mongo-relation');
// UserSchema stores an Array of ObjectIds for posts
var UserSchema = new mongoose.Schema({
posts: [mongoose.Schema.ObjectId],
edited: [mongoose.Schema.ObjectId]
});
// PostSchema stores an ObjectId for the author
var PostSchema = new mongoose.Schema({
title : String
, author : mongoose.Schema.ObjectId
, editor : mongoose.Schema.ObjectId
});
// Attach the plugin
UserSchema.hasMany('Post', {through: 'posts'});
UserSchema.hasMany('Post', {through: 'edited'});
PostSchema.belongsTo('User', {through: 'author'});
PostSchema.belongsTo('User', {through: 'editor'});
var User = mongoose.model('User', UserSchema)
, Post = mongoose.model('Post', PostSchema);
Am I missing something? Or can two models only be associated once?
Thanks!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels