Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I specify the table when using sequelize.col?

Tags:

sequelize.js

My query looks something like

({
  attributes: [[sequelize.fn('COUNT', sequelize.col('id')), 'commitCount']],
  include: [
    {
      model: global.mysqlDb.Commit,
      attributes: ['id'],
      where: {
        RepositoryId: req.params.repositoryId
      }
    }, {
      model: global.mysqlDb.SourceFile
    }
  ],
  group: ['SourceFileId']
});

But the id in the sequelize.col is ambiguous because it could be from any of the tables. Any way for me to specify the table name as well?

like image 535
Shamoon Avatar asked Dec 03 '14 14:12

Shamoon


People also ask

How do I associate a table in Sequelize?

The main way to do this is as follows: Team.hasMany(Player); Player.belongsTo(Team); Again, as mentioned, the main way to do it used a pair of Sequelize associations ( hasMany and belongsTo ).

How do you create table if not exists in Sequelize?

sync(); The call to User. sync() above will cause Sequelize to synchronize the model with the database. The method will create the database table if it doesn't already exist.


1 Answers

You should be able to do sequelize.col('table.column') and then it will automatically be quoted

like image 161
Jan Aagaard Meier Avatar answered Sep 30 '22 04:09

Jan Aagaard Meier