question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Correct way to model.get({plain: true})

See original GitHub issue

Hi, 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:closed
  • Created 7 years ago
  • Comments:20 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
janmeiercommented, May 18, 2016

@sushantdhiman Thanks 😃

I’m wondering whether .toJSON should recursively call toJSON, instead of caling .get on includes - It just feels more natural to override to json than get - But lets close this one in any case

0reactions
sushantdhimancommented, May 18, 2016

Hi @janmeier , this issue can be closed. OP overridden the toJSON on models which resulted the issue.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found