node.js - How can I save relations from request body in nodejs + mongoose application? -
I have 2 models, Category-> Product relationship
In web forms, I have a new product , Selecting a category object. The form sends the category id in the request body. This is my code to save the product:
export.create = function (req, res) {var product = new product (req.body) product.save (function (err) { If res .render ('products / new', {title: 'new product', product: product, errors: utils.errors (err.errors = err)}}}}}
< P> All are okay here. But what do I want, add this product to the "products" field of categories. What is the best way to do this?
Comments
Post a Comment