dimanche 10 juillet 2016

KnexJS Using Array of Columns: "Unhandled rejection Error: ER_BAD_FIELD_ERROR: Unknown column"

We're using an array of column names in knex:

    knex
        .select( ["rowid", "accountid", "accountname"] )
        .from("account")
        .then(function (e, rows) {
            callback(e, rows)
    })

and getting the following error:

select `rowid,accountid,accountname` from `account`

Unhandled rejection Error: ER_BAD_FIELD_ERROR: Unknown column 'rowid,accountid,accountname' in 'field list'

Obviously the column name array has been converted to a string of fields which is causing the error. Using individual fields works correctly:

    knex
        .select( "rowid", "accountid", "accountname" )
        .from('account')
        .then(function (e, rows) {
            callback(e, rows)
    })

Is this a known issue? Is there a workaround for using an array with the 'select' function?

Aucun commentaire:

Enregistrer un commentaire