CLI interface · 0.8.1

CLI: references and collections

Create belongsTo, hasMany and manyToMany relationships and choose how related records are displayed.

On this page

For interactive work, start with the corresponding Generator UI screen. This CLI reference supports scripts and repeatable operations; UI and CLI edit the same model.

Replace ENTITY_NAME, RELATED_ENTITY_NAME and VIRTUAL_ENTITY_NAME with technical names from your model. ENTITY_ROUTE is an API route, TABLE_NAME/JOIN_TABLE_NAME are SQL tables, and RELATION_NAME/COLLECTION_NAME are relationship names. They may differ from the entity name. Commands are templates: do not execute uppercase placeholders literally.

entity relation connects entities that have already been defined. Before adding a relationship, check their primary keys and type compatibility. A reference to RELATED_ENTITY_NAME and a collection of COLLECTION_ENTITY_NAME use different storage methods and therefore different parameters.

Reference to one related entity

Create ENTITY_NAME and RELATED_ENTITY_NAME with identifiers. A reference requires a relation-type field with relationship metadata: a plain int with the same type as the target key is insufficient.

If RELATED_FIELD_NAME does not exist yet, add it:

admingen-cli --path ./docs-demo field add ENTITY_NAME RELATED_FIELD_NAME --type relation \
  --relation-target RELATED_ENTITY_NAME --relation-type belongsTo \
  --relation-foreign-key RELATED_FIELD_NAME --required

Then define the relationship on the owner's side:

admingen-cli --path ./docs-demo entity relation add ENTITY_NAME RELATION_NAME \
  --type belongsTo --target RELATED_ENTITY_NAME --foreign-key RELATED_FIELD_NAME \
  --target-field id --enforce=true --on-delete restrict \
  --on-update restrict --display-field title

--foreign-key is an ENTITY_NAME field and --target-field is the RELATED_ENTITY_NAME primary key. --display-field defines a readable selection label without changing the physical relationship.

Use setNull for a consistently configured optional reference. The field's required and null settings must permit that action.

Collection relationship

admingen-cli --path ./docs-demo entity relation add ENTITY_NAME COLLECTION_NAME \
  --type manyToMany --target COLLECTION_ENTITY_NAME --through JOIN_TABLE_NAME \
  --source-field id --target-field id \
  --inverse-name INVERSE_COLLECTION_NAME --display-field title

--through names the junction table. --source-field and --target-field are the entities' primary keys, not junction-table columns. The inverse name belongs to the same relationship. Do not duplicate it by creating a second manyToMany in the opposite direction.

For hasMany, specify --owner-relation: an existing belongsTo on the target entity. This creates an inverse view without a new foreign key. See relationship model for ownership details.

JOIN_TABLE_NAME is the physical SQL join table. INVERSE_COLLECTION_NAME is the inverse collection name on the target entity; it is not an SQL table name.

Change an existing relationship

admingen-cli --path ./docs-demo entity relation update ENTITY_NAME RELATION_NAME --display-field title

Presentation and physical storage are separate settings. Changing an already generated physical relationship may be prohibited. For generated_relation_change_blocked, inspect which property caused the error and what the message suggests. Forced application does not permit bypassing schema validation.

After saving, check plan/dry-run, run Generate, and apply any required migrations. NOT VALID constraints are checked through generated application commands, not the generator's relation command.

Command reference

Command Invocation
entity relation admingen-cli entity relation [command]
entity relation add admingen-cli entity relation add <entity-name> <relation-name> [flags]
entity relation delete admingen-cli entity relation delete <entity-name> <relation-name> [flags]
entity relation update admingen-cli entity relation update <entity-name> <relation-name> [flags]

Global --path, --output and --help are covered in CLI basics. Replace angle-bracket arguments with your own names. Update preserves omitted properties.

Relationship parameters

Parameter Used by Default Meaning
--display-field VALUE entity relation add, entity relation update empty string Target field for a readable label of a related record.
--enforce entity relation add, entity relation update true For belongsTo, create a PostgreSQL foreign-key constraint.
--foreign-key VALUE entity relation add, entity relation update empty string Source entity field that stores the reference.
--inverse-name VALUE entity relation add, entity relation update empty string Name of the derived inverse many-to-many view; does not create a second owner.
--on-delete VALUE entity relation add, entity relation update empty string Policy for a belongsTo relationship with a foreign-key constraint when the target is deleted: restrict or setNull.
--on-update VALUE entity relation add, entity relation update empty string Policy for a belongsTo relationship with a foreign-key constraint when the target key changes: restrict or cascade.
--owner-relation VALUE entity relation add, entity relation update empty string Name of the owning belongsTo on the target entity for hasMany.
--source-field VALUE entity relation add, entity relation update empty string Source entity PK, not a junction-table column.
--target VALUE entity relation add, entity relation update empty string Target entity of the relationship.
--target-field VALUE entity relation add, entity relation update empty string Target entity PK.
--through VALUE entity relation add, entity relation update empty string Junction-table name for many-to-many.
--type VALUE entity relation add, entity relation update empty string For a field, a supported data type; for a relation, belongsTo, hasMany or manyToMany.
--new-name VALUE entity relation update empty string A new name where the command supports it. A regular update does not rename a persisted field: use Rename.