JSON format for queries using "include"
See original GitHub issueFirst, thanks for the awesome library. Saves me a ton of time in my projects. I’ve had this problem for quite a while and made a bunch of workarounds, finally decided to just ask you guys. Thanks in advance!
Basically i want to query the db and include an association as nest json. EG:
User.findOne({
raw: true,
include: [{
model: Company,
as: 'company'
}]
})
What im getting is:
{
id: 1234,
name: 'Blah',
company.id: 1234,
company.name: 'blah blah'
}
I would expect:
{
id: 1234,
name: 'Blah',
company: {
id: 1234,
name: 'blah blah'
}
}
What am i doing wrong here?
Dialect: postgres Database version: 9.5.2.0 Sequelize version: 3.23.4
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Format Query Results as JSON with FOR JSON - SQL Server
In AUTO mode, the structure of the SELECT statement determines the format of the JSON output. By default, null values aren't included in...
Read more >The JSON_QUERY() function to extract objects from JSON Data
In this article, we will explore JSON_QUERY() functions in SQL Server to extract JSON objects and array from the JSON Data.
Read more >Simple Queries - JSONata Documentation
JSON arrays are used when an ordered collection of values is required. Each value in the array is associated with an index (position)...
Read more >Basics of Working with JSON in SQL Server - {coding}Sight
The document in Listing 1 was extracted from a regular SQL Server database table using the query from Listing 2. Listing 2 shows...
Read more >Query and Manipulate JSON Data with T-SQL - Pluralsight
The decision of whether including a root element or not depends on the needs of the application consuming the result set. In any...
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
another option is set: nest: true
await Empresa.findOne({ where: {}, raw: true, nest: true, attributes: [‘cnpj’, ‘razao_social’, ‘inscricao_estadual’], include: [{}]
Oh, and if it wasn’t clear, of course you can also just
res.json()
the result.