javascript - Sequelize findOne error: TypeError indexOf undefined -


working on using sequelize new db first time, table creation , migrations done through cli (we have legacy db schema using no issue models constructed match existing tables, i'm familiar basic usage). when attempt test query against 1 of new tables typeerror.

system: sequelize v4.5.0, node v8.1.4, npm v5.3.0

first stacktrace:

typeerror: cannot read property 'indexof' of undefined     @ attributes.map.attr (**path**/node_modules/sequelize/lib/dialects/abstract/query-generator.js:1222:27)     @ array.map (native)     @ object.escapeattributes (**path**/node_modules/sequelize/lib/dialects/abstract/query-generator.js:1207:37)     @ object.selectquery (**path**/node_modules/sequelize/lib/dialects/abstract/query-generator.js:979:28)     @ queryinterface.select (**path**/node_modules/sequelize/lib/query-interface.js:672:27)     @ promise.try.then.then.then (**path**/node_modules/sequelize/lib/model.js:1539:34)     @ trycatcher (**path**/node_modules/bluebird/js/release/util.js:16:23)     @ promise._settlepromisefromhandler (**path**/node_modules/bluebird/js/release/promise.js:512:31)     @ promise._settlepromise (**path**/node_modules/bluebird/js/release/promise.js:569:18)     @ promise._settlepromise0 (**path**/node_modules/bluebird/js/release/promise.js:614:10)     @ promise._settlepromises (**path**/node_modules/bluebird/js/release/promise.js:693:18)     @ async._drainqueue (**path**/node_modules/bluebird/js/release/async.js:133:16)     @ async._drainqueues (**path**/node_modules/bluebird/js/release/async.js:143:10)     @ immediate.async.drainqueues (**path**/node_modules/bluebird/js/release/async.js:17:14)     @ runcallback (timers.js:800:20)     @ tryonimmediate (timers.js:762:5)     @ processimmediate [as _immediatecallback] (timers.js:7 

the code straightforward connection test. inject dependencies , attempt query.

query code:

#!/usr/bin/env node 'use-strict';  const errormessage = require('../../../util/error-msg');  class sync {   constructor(db, log) {     this.db = db;     this.log = log;   }    async getbatch() {     try {       let result =  await this.db.shopifypricerule.findone({where: {id: 1}});        return result;     } catch (error) {       let msg = errormessage(error, 'sync.getbatch');       this.log.error({ error: msg }, error.message);     }   } }  module.exports = sync; 

connection:

#!/usr/bin/env node 'use-strict';  const sequelize = require('sequelize'); const fs = require('fs'); const path = require('path');  module.exports = function makeconnection(env, log, dir, indexfile) {   let db = {};    try {     env.logging = msg => log.trace({sequelize: msg});     let sequelize = new sequelize(env);      fs.readdirsync(dir)       .filter(file => ((file.indexof('.') !== 0) && (file !== indexfile) && (file.slice(-3) === '.js')))       .foreach(key => {         const model = sequelize.import(path.join(dir, key));         db[model.name] = model;       });      object.keys(db).foreach(modelname => {       if (db[modelname].associate) {         db[modelname].associate(db);       }     })      sequelize.authenticate()       .then(() => log.info('db connection has been established schema.'))       .catch(err => log.error({ err: err }, 'unable connect db'));       db.sequelize = sequelize;     db.sequelize = sequelize;      return db;   } catch (error) {     log.error({error: error});   } } 

model

'use strict'; module.exports = function(sequelize, datatypes) {   var shopifypricerule = sequelize.define('shopifypricerule', {     channel_id: datatypes.string,     promo_id: datatypes.integer,     title: datatypes.string,     target_type: datatypes.string,     target_selection: datatypes.string,     allocation_method:datatypes.string,     once_per_customer: datatypes.boolean,     customer_selection: datatypes.string,     entitled_product_ids: datatypes.json,     entitled_variant_ids: datatypes.json,     entitled_collection_ids: datatypes.json,     entitled_country_ids: datatypes.json,     prerequisite_saved_search_ids: datatypes.json,     prerequisite_subtotal_range: datatypes.json,     prerequisite_shipping_price_range: datatypes.json   });    shopifypricerule.associate = models => {     shopifypricerule.belongsto(models.promo)   };    return shopifypricerule; }; 

what i've tried

  • reading similar questions on
  • reading similar issues in sequelize's github issue page
  • trying connect table in same schema
  • trying select on other columns (just in case default id field not being in model issue)
  • raw query on same table, works expected

positive i'm overlooking super basic thing here, can't see it.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -