[v6] Proper way to use model classes in commands #4501
-
I have a command where I would like retrieve a collection of records using Lucid. It looks something like this: export default class TestCommand extends BaseCommand {
public static commandName = "test:command";
static options: CommandOptions = {
loadApp: true,
staysAlive: false,
};
public async run() {
const { default: MyModel } = await import("#models/my_model");
const myModels = await MyModel.query().where("some", "condition");
}
} I'm getting the following error:
I have also tried importing the model class at the top of the file like: import MyModel from "#models/my_model"; which results in the same error. Importing the model using either method and
Is there a different way I'm supposed to be importing model classes? I wasn't able to find any reference to this in the documentation. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Can you share your |
Beta Was this translation helpful? Give feedback.
-
It should be See https://docs.adonisjs.com/guides/ace-creating-commands#command-metadata |
Beta Was this translation helpful? Give feedback.
It should be
startApp
, notloadApp
See https://docs.adonisjs.com/guides/ace-creating-commands#command-metadata