0

Is there any possible way to add multiple values to the column? Right now i have a comments column and I have this code .

app.put('/addComment/:id', (req, res) => {

Posts.update({
        comment: req.body.comment
    },
    {
        where: {
            id: req.params.id
        }
    }).then((post) => {
    res.send(post)
}).catch((err) => {
    console.log("err", err);
});
})

But instead of adding another value it just updates old one with new , any suggestions on method which will solve my issue?

4
  • What do you mean by multiple values? Is your column a text? Do you wish to concatenate an existing text in the column with a new one? Commented Jul 7, 2020 at 6:57
  • if you want to add another value why your using update method? update method used to change the value of existing. Commented Jul 7, 2020 at 6:59
  • the column data_type is text[],I know i should not use update but I'm new to sequelize and I could not find any other method which would suit my proble Commented Jul 7, 2020 at 7:00
  • Could you suggest me method which would solve this? Commented Jul 7, 2020 at 7:00

1 Answer 1

2

You can use concat function sequelize

It will append new value into the column.

const {fn, col } = models.sequelize

Posts.update({
 members: fn('CONCAT', col("comment"), req.body.comment)
}, {
 where: {
  id: req.params.id
 }
}).then(function() {
 console.log("Value Appended");
});

Sign up to request clarification or add additional context in comments.

2 Comments

import Sequelize
Ya! it is saved in a single column but is it possible to display it separately in a card view?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.