Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
136
rated 0 times [  139] [ 3]  / answers: 1 / hits: 30093  / 8 Years ago, sun, july 17, 2016, 12:00:00

I am trying to add a property to a sequelize instance before passing it back to the client.



router.get('/cats/1', function (req, res) {
Cat.findOne({where: {id: 1}})
.then(function (cat) {
// cat exists and looks like {id: 1}
cat.name = Lincoln;
// console.log of cat is {id: 1, name: Lincoln}
res.json(cat);
});
});


The client only see's {id: 1} and not the newly added key.




  • What is going on here?

  • What type of Object is returned by Sequelize?

  • How can I add new properties to my Cats and send them back?


More From » postgresql

 Answers
16

The following works for sequelize v4.



...
const order = Order.findOne(criteria);
order.setDataValue('additionalProperty', 'some value');
...


Hope this helps. It's a bit late but in case people are still looking for answers.


[#61331] Friday, July 15, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
iliana

Total Points: 246
Total Questions: 109
Total Answers: 82

Location: Palestine
Member since Tue, Jul 20, 2021
3 Years ago
iliana questions
;