ModelArray#toObject Still Returning ModelArray
AlanBreck opened this issue · 0 comments
AlanBreck commented
When running the following code, .toObject() still returns a ModelArray, but with plain objects.
Job.query()
.where( jobIds.map( v => ( { id: v } ) ) )
.orderBy( "id", "ASC" )
.end(( err, models ) => {
const jobsToInvoice = models.toObject().map( job => ({
name: job.name,
quantity: 1,
unit_price: {
currency: "USD",
value: job.cost
}
}));
console.log( jobsToInvoice );
});
Output
ModelArray [
{ name: 'Awesome Project',
quantity: 1,
unit_price: { currency: 'USD', value: 0 } },
{ name: 'Awesome Project 3',
quantity: 1,
unit_price: { currency: 'USD', value: 0 } },
{ name: 'Awesome Project 4',
quantity: 1,
unit_price: { currency: 'USD', value: 0 } },
_meta: { total: 0, offset: 0 },
Model: 3 ]