generate:model
If you are looking to generate a resourceful (CRUD) controller with a model, see the resource generator documentation.
To generate an STI child model, see the sti-child generator documentation.
The generate:model CLI documentation follows below, but more details about generating a model are included in the model generator documentation.
Usage
pnpm psy g:model [options] <modelName> [columnsWithTypes...]
Arguments
-
<modelName>: The name of the model to create, e.g.PostorSettings/CommunicationPreferences. -
[columnsWithTypes...]: Space separated snake-case (except for belongs_to model name) properties like this:title:citext subtitle:string body_markdown:text style:enum:post_styles:formal,informal User:belongs_toAll properties default to not nullable; null can be allowed by appending
:optional:subtitle:string:optionalSupported types
citext,citext[]: case insensitive text (indexes and queries are automatically case insensitive)string,string[]: varchar; allowed length defaults to 255, but may be customized, e.g.:subtitle:string:128orsubtitle:string:128:optionaltext,text[]date,date[]datetime,datetime[]integer,integer[]decimal,decimal[]: scale,precision is required, e.g.:volume:decimal:3,2orvolume:decimal:3,2:optional- Leveraging arrays, add the "[]" suffix, e.g.:
volume:decimal[]:3,2
- Leveraging arrays, add the "[]" suffix, e.g.:
enum,enum[]: include the enum name to automatically create the enum:type:enum:room_types:bathroom,kitchen,bedroomortype:enum:room_types:bathroom,kitchen,bedroom:optional- Omit the enum values to leverage an existing enum (omits the enum type creation):
type:enum:room_typesortype:enum:room_types:optional - Leveraging arrays, add the "[]" suffix, e.g.:
type:enum[]:room_types:bathroom,kitchen,bedroom
- Omit the enum values to leverage an existing enum (omits the enum type creation):
belongs_to: not only adds a foreign key to the migration, but also adds a BelongsTo association to the generated model:- Include the fully qualified model name, e.g., if the Coach model is in
src/app/models/Health/Coach:Health/Coach:belongs_to
- Include the fully qualified model name, e.g., if the Coach model is in
Options
--no-serializer: Do not generate a serializer for the model.--connection-name <connectionName>: The db connection you want this attached to (defaults to the default db connection) (default: "default").--sti-base-serializer: Generate a base serializer for STI.-h, --help: Display help for command.