Implement "flattening" when including fields in an association table
See original GitHub issueI am not sure how to title this issue, but let me explain.
Suppose we have two tables Person and Project plus a Role association connecting a person with one or more projects (in both directions). The Role association/table has a field called say RoleType.
I could set this up and query the db with for example:
Person.find({
where: { id: 1 },
include: [
{ model: Project, as: "projects", attributes: ["id", "name"], though: { attributes: "roleType" } }
]
})
which could produce something like
{
name: "John Smith",
id: 1,
project: [ { id: 'a', name: 'Fix issue', role: { roleType: "manager" } }]
}
My issue is about the sub object role: { roleType: "manager" }. What I would like is a return similar to this:
{
name: "John Smith",
id: 1,
project: [ { id: 'a', name: 'Fix issue', roleType: "manager" } ]
}
Namely I would like the roleType field to be available directly on each project item.
Is this possible to achieve? It would be nice to have it. Any suggestions for work arounds?
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:11 (1 by maintainers)
Top Results From Across the Web
Flattening columns in sub associations with sequelize
I have solved by using sequelize literal, it's a little raw but it works but you must know all associations before the column....
Read more >FLATTEN Data Using Google BigQuery's Legacy vs ...
This acts similarly to Entity SQL's FLATTEN function by purposefully flattening the specified field into the rest of the dataset.
Read more >LWC Relationship fields in data table, flattening in @wire
I am struggling with relationship fields in a datatable using Lightning Web Components. I am querying through Apex and returning a list from ......
Read more >Part#8. CDS Views – Joins and Associations
We saw that how a CDS view fetched data from 2 tables with the ... the business user is looking at only fields...
Read more >Creating Flatten Views — Virtual DataPort Administration ...
If you need to “flatten” the fields of a register and not an array, do not create a Flatten view. Instead, create a...
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

Sorry to ‘resurrect’ this issue, but may I ask if this is implemented in sequelize now, as I couldn’t find it in documentation?
Yes, you can add option
raw : trueso it becomes like:And you can have a result like: