Last active
August 29, 2018 02:31
-
-
Save Tinusw/1bcfa7790d04bcf123d6be8e94a4e3bc to your computer and use it in GitHub Desktop.
Revisions
-
Tinusw revised this gist
Mar 13, 2018 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,13 +7,13 @@ mongoose.Promise = global.Promise; exports.createStore = (req, res) => { const store = new Store(req.body); const record_we_want_to_associate .findOne({ id: req.params._id}) .catch(err => { throw Error(err); }); store.storeb_id = record_we_want_to_associate._id store .save() -
Tinusw created this gist
Mar 13, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ const mongoose = require('mongoose'); const Store = mongoose.model('Store'); const StoreB = mongoose.model('StoreB'); // Tells package to use es6 promises mongoose.Promise = global.Promise; exports.createStore = (req, res) => { const store = new Store(req.body); let association .findOne({ id: req.params._id}) .catch(err => { throw Error(err); }); store.storeb_id = association._id store .save() // after save return all records .then(stores => { return Store.find() }) // then display them on index page .then(stores => { res.render('index', {stores: stores} } // deal with errors .catch(err => { throw Error(err) } }