Mix.Tasks.Phoenix.Gen.Model
Generates an Ecto model in your Phoenix application.
mix phoenix.gen.model User users name:string age:integer
The first argument is the module name followed by its plural name (used for the schema).
The generated model will contain:
- a model in web/models
- a migration file for the repository
Attributes
The resource fields are given using name:type
syntax
where type are the types supported by Ecto. Ommitting
the type makes it default to :string
:
mix phoenix.gen.model User users name age:integer
The generator also supports belongs_to
associations:
mix phoenix.gen.model Post posts title user:belongs_to
This will result in a migration with an :integer
column
of :user_id
and create an index. It will also generate
the appropriate belongs_to
entry in the model’s schema.
Furthermore an array type can also be given if it is supported by your database, although it requires the type of the underlying array element to be given too:
mix phoenix.gen.model User users nicknames:array:string
Namespaced resources
Resources can be namespaced, for such, it is just necessary to namespace the first argument of the generator:
mix phoenix.gen.model Admin.User users name:string age:integer
Summary↑
run(args) | Callback implementation of |
Functions
Callback implementation of Mix.Task.run/1
.