irzum shahid
irzum shahid

Reputation: 200

Sequelize FindAll()

I am using sequelize to get data from mySql db. thats how am using it

const isProduct = await models.product.findAll({
  where: { prod_id: prodId },
});

but the result data is improper object i.e

 ==>> [ product {
┃     dataValues:
┃      { id: 18,
┃        prod_id: 'gid://shopify/Product/6163962757308',
┃        price: '167' },
┃     _previousDataValues:
┃      { id: 18,
┃        prod_id: 'gid://shopify/Product/6163962757308',
┃        price: '167' },
┃     _changed: Set {},
┃     _options:
┃      { isNewRecord: false,
┃        _schema: null,
┃        _schemaDelimiter: '',
┃        raw: true,
┃        attributes: [Array] },
┃     isNewRecord: false } ]

if you notice line no.1 there is no ":" after product

 [ product {

am I doing something wrong?

Upvotes: 0

Views: 393

Answers (1)

const isProduct = await models.product.findAll({
  where: { prod_id: prodId },
  raw: true,
});

With the "raw: true" option you can get the plain object instead of the Sequelize model.

Upvotes: 1

Related Questions