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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -