Home > OS >  Accessing data from ORM in pug
Accessing data from ORM in pug

Time:04-27

I have a question, when I pass an Instance to the Pug file I just access the object passed as

 each row in headings
  tr
   td= row.id

while the objects is wrapped under an object itself, so how I am able to access the id just row.id and I am getting the same result with row.dataValues.id

Book {
    dataValues: {
      id: 10,
      title: 'Frankenstein',
      author: 'Mary Shelley',
      genre: 'Horror',
      year: 1818,
      createdAt: Invalid Date,
      updatedAt: Invalid Date
    },
    _previousDataValues: {
      id: 10,
      title: 'Frankenstein',
      author: 'Mary Shelley',
      genre: 'Horror',
      year: 1818,
      createdAt: Invalid Date,
      updatedAt: Invalid Date
    },
    uniqno: 1,
    _changed: Set(0) {},
    _options: {
      isNewRecord: false,
      _schema: null,
      _schemaDelimiter: '',
      raw: true,
      attributes: [Array]
    },
    isNewRecord: false
  }

CodePudding user response:

Use get({ plain: true}) method on a model instance to get a plain object.

const book = await Books.findOne({
  // options
})
const plainBook = book.get({ plain: true})
  • Related