Important:Before running this generator, you must create an application using the application generator.Then you must run the command from the root directory of the application.

Synopsis

Adds a new Model class to a LoopBack application.

  1. lb4 model [options] [<name>]

Options

—base : (Optional) a valid model already created in src/models or any ofthe core based class models Entity or Model. Your new model will extend thisselected base model class.Standard options

  • -h, —help
  • Print the generator’s options and usage.
  • —skip-cache
  • Do not remember prompt answers. Default is false.
  • —skip-install
  • Do not automatically install dependencies. Default is false.
  • -c, —config
  • JSON file name or value to configure options
  • —format
  • Format generated code using npm run lint:fixFor example,
  1. lb4 app --config config.json
  2. lb4 app --config '{"name":"my-app"}'
  3. cat config.json | lb4 app --config stdin
  4. lb4 app --config stdin < config.json
  5. lb4 app --config stdin << EOF
  6. > {"name":"my-app"}
  7. > EOF
  • -y, —yes
  • Skip all confirmation prompts with default or provided value

Arguments

<name> - Required name of the model to create as an argument to the command.If provided, the tool will use that as the default when it prompts for the name.

Interactive Prompts

The tool will prompt you for:

  • Name of the model.(modelName) If the name had been supplied from thecommand line, the prompt is skipped and the datasource is built with the namefrom the command-line argument.

  • Model base class.(modelBaseClass) If the command line option –base hadbeen supplied with a valid model class name, the prompt is skipped. It willpresent you with a list of available models from src/models including theEntity and Model at the top of the list.

    • An Entity is a persisted model with an identity (ID).
    • A Model is a business domain object.
    • For more information, seehere.
  • Allow additonal properties.(allowAdditionalProperties) Defaults tofalse. To allow arbitrary properties in addition to well-definedproperties, disable strict mode.

The tool will next recursively prompt you for the model’s properties until ablank one is entered. Properties will be prompted for as follows:

  • Name of the property. To add a property, enter a name here. To end theproperty prompt loop, leave this blank and press enter.
  • Property type. Select the type for the property from the followingoptions: string, number, boolean, object, array, date, buffer,geopoint, any.
  • Is ID Field. Defaults to no. If the property is the ID for the Model,enter Y or yes. This will only be prompted until a property is markedas the id for the Model.
  • Required. Defaults to no. If the property is required, enter Y oryes.
  • Default value. Set a default value for the property if one isn’t supplied.Leave blank otherwise.

Output

Once all the prompts have been answered, the CLI will do the following:

  • Create a Model class as follows: /src/models/${modelName}.model.ts
  • Update /src/models/index.ts to export the newly created Model class.