node.js - Sequelize where has NOT -
i have article
sequelize model articles relate each other. articles translated copies of other articles. relation setup so:
var article = sequelize.define('article', { type : datatypes.enum('source', 'translated'), sourcearticleid : datatypes.integer }); db.article.hasmany(db.article, { foreignkey: 'sourcearticleid', : 'translatedarticles' });
so, article type = 'source'
can have many translatedarticles
type = 'translated'
.
now, want query source
articles not have translation.
based on an issue @ sequelize project github, accomplished so:
article.findone({ where: sequelize.literal('translatedarticles.sourcearticleid null'), include: [ { model: article, : 'translatedarticles' } ] });
yet when run get:
sequelizedatabaseerror: er_bad_field_error: unknown column 'translatedarticles.sourcearticleid' in 'where clause'
i've tried variations in naming, including translatedarticles.sourcearticleid
, articles.sourcearticleid
, , articles.sourcearticleid
.
am missing something?
note temporarily work around problem using literal not exists query, so:
article.findone({ where: sequelize.literal('not exists (select id articles article.id = articles.sourcearticleid limit 1)') });
i don't know database technology using on backend guessing case-sensitive. believe isn't finding field because need capitalize t in translatedarticles. should work:
article.findone({ where: sequelize.literal('translatedarticles.sourcearticleid null'), include: [ { model: article, : 'translatedarticles' } ] });
Comments
Post a Comment