Correct way to model.get({plain: true})
See original GitHub issueHi,
I have a findAll() query that returns array. I am struggling with correct way to place
model.get({plain: true})
. Do i have to iterate over array and call .get() on each individual object or is there a way to specify this inside model class.
Right now what i am doing is i have a classMethod call trimMeta(array) which iterates over and perform
model.get({plain: true})
. But doing this cause toJSON() [instanceMethod] to never invoke.
Issue Analytics
- State:
- Created 7 years ago
- Comments:20 (11 by maintainers)
Top Results From Across the Web
Sequelize, convert entity to plain object - Stack Overflow
If you don't want to use { raw: true } in the query, the preferred approach is to call .get() on the results....
Read more >Model - Sequelize
Model instances operate with the concept of a dataValues property, which stores the actual values represented by the instance. By default, the values...
Read more >Sequelize tutorial - JavaScript ORM programming ... - ZetCode
Sequelize tutorial shows how to program databases in JavaScript with ... findById(2).then((note) => { console.log(note.get({ plain: true })) ...
Read more >How to Check if Object is Empty in JavaScript - Samantha Ming
It's just regular, plain JavaScript without the use of a library like Lodash or jQuery. # A. Empty Object Check in Newer Browsers....
Read more >Learn Sequelize in 7 Minutes: Part 1 | by Shraddha Paghdar
Models can be defined in two equivalent ways in Sequelize: ... and receive a plain response instead, pass { raw: true } as...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@sushantdhiman Thanks 😃
I’m wondering whether
.toJSON
should recursively calltoJSON
, instead of caling.get
on includes - It just feels more natural to override to json than get - But lets close this one in any caseHi @janmeier , this issue can be closed. OP overridden the
toJSON
on models which resulted the issue.