From 6264fa57110a73be0b7ca40fce1a6d0e15e6534c Mon Sep 17 00:00:00 2001 From: drillprop Date: Tue, 26 Feb 2019 20:55:51 +0100 Subject: [PATCH] assign albums to user only --- src/graphql/resolvers/Mutation.js | 10 ++++++++-- src/models/User.js | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/graphql/resolvers/Mutation.js b/src/graphql/resolvers/Mutation.js index 714405d..dab804a 100644 --- a/src/graphql/resolvers/Mutation.js +++ b/src/graphql/resolvers/Mutation.js @@ -12,8 +12,14 @@ const Mutation = { throw new Error('Sign in to add a cd'); } let { title, artist, image } = args; - const album = new Album({ title, artist, image }); - await album.save(); + console.log(user._id); + const album = new Album({ + title, + artist, + image + }); + await user.albums.push(album); + user.save(); return album; }, signup: async (parent, args, ctx, info) => { diff --git a/src/models/User.js b/src/models/User.js index d90e5b5..93b962c 100644 --- a/src/models/User.js +++ b/src/models/User.js @@ -6,7 +6,7 @@ const userSchema = new Schema({ password: { type: String, required: true }, date: { type: Date, default: Date.now }, avatar: String, - albums: [{ type: Schema.Types.ObjectId, ref: 'Album' }] + albums: [] }); const User = model('Users', userSchema);