adonisjs / lucid

AdonisJS SQL ORM. Supports PostgreSQL, MySQL, MSSQL, Redshift, SQLite and many more
https://lucid.adonisjs.com/
MIT License
1.06k stars 190 forks source link

Calling to model from ace command with error #441

Closed RFContracts closed 5 years ago

RFContracts commented 5 years ago

Arise error "Class constructor Transaction cannot be invoked without 'new'" with following code in ace command

'use strict'

const { Command } = require('@adonisjs/ace')
const Transaction = use('App/Models/Transaction')

class ParseTx extends Command {
  static get signature () {
    return 'parse:tx'
  }

  static get description () {
    return 'Tell something helpful about this command'
  }

  async handle (args, options) {
    this.info('Dummy implementation for parse:tx command')
    await Transaction().find(1)
  }
}

module.exports = ParseTx

Transaction.js

'use strict'

/** @type {typeof import('@adonisjs/lucid/src/Lucid/Model')} */
const Model = use('Model')

class Transaction extends Model {
  static boot() {
    super.boot()

    /**
     * A hook to calculate token balance
     *
     * Look at `app/Models/Hooks/Transaction.js` file
     */
    this.addHook('afterCreate', 'Transaction.calculateTokenBalance')
  }

}

module.exports = Transaction

node version is v10.15.3

package.json

"dependencies": {
    "@adonisjs/ace": "^4.0.7",
    "@adonisjs/auth": "^3.0.7",
    "@adonisjs/bodyparser": "^1.0.8",
    "@adonisjs/cors": "^1.0.2",
    "@adonisjs/fold": "^4.0.5",
    "@adonisjs/framework": "^4.0.27",
    "@adonisjs/ignitor": "^2.0.8",
    "@adonisjs/lucid": "^4.0.22",
    "@adonisjs/session": "^1.0.23",
    "@adonisjs/shield": "^1.0.4",
    "@adonisjs/validator": "^5.0.6",
    "@adonisjs/websocket": "^1.0.11",
    "@adonisjs/websocket-client": "^1.0.9",
    "@nuxtjs/auth": "^4.5.3",
    "@nuxtjs/axios": "^5.4.1",
    "@nuxtjs/dotenv": "^1.3.0",
    "bootstrap": "^4.3.1",
    "bootstrap-vue": "^2.0.0-rc.11",
    "bp-vuejs-dropdown": "^2.1.1",
    "cross-env": "^5.2.0",
    "desandro-matches-selector": "^2.0.2",
    "ev-emitter": "^1.1.1",
    "fizzy-ui-utils": "^2.0.7",
    "flickity": "^2.2.0",
    "get-size": "^2.0.3",
    "gsap": "^2.1.2",
    "imagesloaded": "^4.1.4",
    "jquery": "^3.4.1",
    "lodash": "^4.17.11",
    "nuxt": "^2.4.0",
    "pg": "^7.10.0",
    "popper": "^1.0.1",
    "ssr-window": "^1.0.1",
    "tap-listener": "^2.0.0",
    "unidragger": "^2.3.0",
    "unipointer": "^2.3.0",
    "vue-clickaway": "^2.2.2",
    "web3": "^1.0.0-beta.55"
  },

What im doing wrong?

thetutlage commented 5 years ago

Issue doesn't adhere to the guidelines of creating a proper issue.

  1. Make sure that you are only reporting bugs or submitting feature requests on Github.
  2. In case of feature requests, please be descriptive and explain how this feature helps a broader audience and not just you.

If you are not submitting a bug and neither a feature request, then please use the forum or discord server

In any case, issues which are not descriptive enough will be closed. Please respect our time.