Skip to main content

DevTools: Model

tip

DevTools includes a fully featured Model Creation Routine which we will detail here

Starting off

To start, simply run econsor:dev:addmodel.

It will ask you for the following Infos:

  • Plugin - Select the Plugin you want to add the CMS to (type in the corresponding number)
  • Model Name - This is the Name used in Filenames and Namespaces, so for example type MyModel
  • Table Name - This is used as the SQL table name, so for example type ec_my_model
  • Translated? - This will make your model a translated model and also generate a corresponding translation Model

Adding Fields

You're now being asked if you want to add fields. If you choose y, you have the following options:

Regular Fields

tip

If you pick any of these you will be asked for the Field Name - The Field name in camelCase - For example myBoolField

You have the choice between these data types - They should be self-explanatory:

  • bool
  • int
  • float
  • string
  • longtext
  • array (/JSON Field)
  • id (necessary for associations and references)
  • date

Associations

tip

You can create Associations to other Entities by choosing one of these options:

  • association - one to one
  • association - one to many
  • association - many to one
  • association - many to many

Translated Field

tip

You need to have Translated? selected in the model creation in the previous step for this to be pickable.

danger

If you pick this, you will then be asked what type the field should be. From there on it's like it's a normal field. (See above/below)

  • Translated Field

Other

  • exit - Quit Routine

Associations

If you have chosen an Association Field it will ask you for these infos (in our example we want to link a field in our entity called image to the id Field in the Media Entity):

  • Target Entity Name: The Entity the Association points to - In our example this is MediaEntity
  • Field Name: The name of the Field we're creating in OUR Entity - In our example this is image. Please note: The corresponding field for the 'id' will be created automatically.
  • Target Table Name: The SQL name of our target table - In our example this is media
  • Target Field Name: The SQL name of our target field - In our example this is id
  • Target Definition Name: The name of our Target Entity Definition - In our example this is MediaDefinition
  • Target Entity Field Name: The name of the target field in the Definition - In our example this is also id but be aware other field names will be in camelCase instead of snake_case.