sequelize.js - Sequelize group by with association includes id -


so when requesting group sequelize follows:

return models.workingcalendar             .findall({                 attributes: [                     'workingcalendar.periodid',                     'workingcalendar.date',                     'period.name'                 ],                 include: [                     {                         model: models.period,                         attributes: []                     }                 ],                 where: {                     getsudoid: currentgetsudo.id,                     unitplantid: unitplantid                 },                 group: ['workingcalendar.periodid',                     'workingcalendar.date',                     'period.name'],             }); 

sequelize run query:

select  [workingcalendar].[id], [workingcalendar].[periodid],  [workingcalendar].[date],  [period].[name]  [workingcalendars] [workingcalendar]  left outer join [periods] [period] on [workingcalendar].[periodid] = [period].[id]  [workingcalendar].[getsudoid] = 1 , [workingcalendar].[unitplantid] = n'1'  group [workingcalendar].[periodid], [workingcalendar].[date], [period].[name]; 

yet never asked workingcalender.id , cannot seem rid of that. how make sure sequelize not getting me id workingcalendar?

i've found associations attributes should empty array , works not main object since need 3 columns.

so not possible. orm needs relation towards database , done through id; making impossible without id.

what can do, however, raw query sequelize.

i.e.

return models.sequelize.query(     `select      [workingcalendar].[id],     [workingcalendar].[periodid],      [workingcalendar].[date],      [period].[name]      [workingcalendars] [workingcalendar]      left outer join [periods] [period] on [workingcalendar].[periodid] = [period].[id]      [workingcalendar].[getsudoid] = :getsudoid , [workingcalendar].[unitplantid] = n'1'      group [workingcalendar].[periodid], [workingcalendar].[date], [period].[name]`,     {         replacements: { getsudoid: getsudoid },         type: models.sequelize.querytypes.select     } ) 

hope helps struggling too.


Comments

Popular posts from this blog

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -

c++ - Migration from QScriptEngine to QJSEngine -