The %command.name% command creates or updates an entity and repository class.
php %command.full_name% BlogPost
If the argument is missing, the command will ask for the entity class name interactively.
You can also mark this class as an API Platform resource. A hypermedia CRUD API will
automatically be available for this entity class:
php %command.full_name% --api-resource
Symfony can also broadcast all changes made to the entity to the client using Symfony
UX Turbo.
php %command.full_name% --broadcast
You can also generate all the getter/setter/adder/remover methods
for the properties of existing entities:
php %command.full_name% --regenerate
You can also *overwrite* any existing methods:
php %command.full_name% --regenerate --overwrite
Fields can be passed on the command line instead of being asked for, which is
what you want in a script or when the terminal is not interactive:
php %command.full_name% BlogPost --field=title:string:100 --field=body:text --field=publishedAt:datetime_immutable?
The format is name[:type[:length]], with a trailing ? to make the field nullable.
The type defaults to the same guess the interactive mode makes, so --field=createdAt
becomes a datetime_immutable. For decimal, the third and fourth parts are the
precision and the scale: --field=price:decimal:10:2.
For enum, the third part is the backed enum class. Its short name is enough as
long as it is unique within src/, which saves escaping backslashes in your shell.
Append ,multiple to store several values:
php %command.full_name% BlogPost --field=status:enum:Status --field=labels:enum:Label,multiple
Relations use their own option, name:type:target, where the target is an entity
class - its short name is enough:
php %command.full_name% BlogPost --relation=author:ManyToOne:User --relation=tags:ManyToMany:Tag
A trailing ? makes the relation nullable here too. Note that this differs from the
interactive mode, which offers nullable as its default answer: without a ? the
relation is NOT NULL.
By default the property added to the other class is named after this entity, and a
OneToOne does not add one at all - the interactive mode advises against it, because
Doctrine cannot lazy load an inverse OneToOne. Both are controlled with
target-field, and orphan-removal activates orphanRemoval on the relations that
support it:
php %command.full_name% BlogPost --relation=cover:OneToOne:Media,target-field=post
php %command.full_name% BlogPost --relation=author:ManyToOne:User,target-field=none
php %command.full_name% BlogPost --relation=comments:OneToMany:Comment,orphan-removal