Sequelize: Sequelize.col in where does not work

Created on 1 Sep 2015  路  3Comments  路  Source: sequelize/sequelize

hi, i use Sequelize.col in where like this:

    Info.findOne(
        include: [
            {
                model: Version,
                where: {
                    versionId: Sequelize.col('Info.current_version')
                }
            }
        ]
    );

    Info.hasMany(Version, {

        foreignKey: 'activity_id'
    });
    Version.belongsTo(Info, {

        foreignKey: 'activity_id'
    });

but, the sql is:

    select 
        ...
    from
        `info` AS `Info` 
LEFT OUTER JOIN `version` AS `Versions` 
ON `Info`.`activity_id` = `Versions`.`activity_id` 
AND `info`.`current_version`

the sql i think should be:

    select 
        ...
    from
        `info` AS `Info` 
LEFT OUTER JOIN `version` AS `Versions` 
ON `Info`.`activity_id` = `Versions`.`activity_id` 
AND `version`.`version_id` =  `info`.`current_version`

So, what problem with this? How I can fix this? Thx~~

bug

Most helpful comment

@mickhansen I spent hours searching for this event it was right in front of my eyes. Shouldn't this be documented well?

All 3 comments

Yep, thats a bug

In the meantime, you can do sequelize.where(Sequelize.col('versionId'), Sequelize.col('Info.current_version'))

Use {$col: 'Info.current_version}

@mickhansen I spent hours searching for this event it was right in front of my eyes. Shouldn't this be documented well?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

maplesap picture maplesap  路  3Comments

davidleureka picture davidleureka  路  3Comments

mwain picture mwain  路  3Comments

hendrul picture hendrul  路  3Comments

jpodwys picture jpodwys  路  3Comments