Site ↗
Documentation sections
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

entity relation connects entities that have already been defined. Before adding a relationship, check their primary keys and type compatibility. An article's reference to a section and its tag list use different storage methods and therefore different parameters.

Reference from an article to one section

Create Article and Section 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 sectionId does not exist yet, add it:

admingen-cli --path ./docs-demo field add Article sectionId --type relation \
  --relation-target Section --relation-type belongsTo \
  --relation-foreign-key sectionId --required

Then define the relationship on the owner's side:

admingen-cli --path ./docs-demo entity relation add Article section \
  --type belongsTo --target Section --foreign-key sectionId \
  --target-field id --enforce=true --on-delete restrict \
  --on-update restrict --display-field title

--foreign-key is an Article field and --target-field is the Section 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.

Tag collection

admingen-cli --path ./docs-demo entity relation add Article tags \
  --type manyToMany --target Tag --through article_tags \
  --source-field id --target-field id \
  --inverse-name articles --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.

Change an existing relationship

admingen-cli --path ./docs-demo entity relation update Article section --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.