I have a raw query like
squelize.query(
`select "order".id, "orderCustomer".id as "orderCustomer.id", "orderCustomer".forename as "orderCustomer.forename"
from orders as "order"
join customers as "orderCustomer" on "orderCustomer".id = "order"."orderCustomerId"
where "orderCustomer".forename ilike '%petra%';`,
{
type: Sequelize.QueryTypes.SELECT,
model: order,
nest: true,
mapToModel: true
})
When I query this in psql I get a correct result set:
-[ RECORD 1 ]----------+------
id | 383
orderCustomer.id | 446
orderCustomer.forename | Petra
-[ RECORD 2 ]----------+------
id | 419
orderCustomer.id | 9
orderCustomer.forename | Petra
The problem is, that Sequelize is apparently not able to form this into an Array of the kind
[
{
id: 383,
orderCustomer: {
id: 446,
forename: 'Petra'
}
},
...
]
Instead I get something like this:
[
{
id: 383,
'orderCustomer.id': 446,
'orderCustomer.forename': 'Petra'
},
...
]
Do I need to include the customer-model in the query's option-object?
UPDATE
I logged the result of my query. There is this property _options on all of the returned order-instances:
_options:{
isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
raw: true, // <--------- possible cause?
attributes: undefined
}
Somehow, I cannot set options.raw to false on my query definition! Maybe that is the reason why …
…sequelize will not try to format the results of the query, or build an instance of a model from the result (see docs > query() > options.raw)
Any ideas?