'Accessing data from ORM in pug
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
}
Solution 1:[1]
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})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Anatoly |
