Doctrine
Full support for Doctrine including entity classes and migrations is supported if that's your preferred way of managing the database. Below explains all you need to know in order to utilize Doctrine within Apex.
bootDoctrine()
To use Doctrine during a request, you must run the App::bootDoctrine method, which returns an instance of Doctrine's EntityManager class. For example, when you need a copy of EntityManager simply run:
$manager = $app->bootDoctrine();
Entity Directories
If you create all entity classes via the apex
CLI tool (see below), then when Doctrine is booted the EntityManager will be instantiated with all necessary entity directories with no additional work required on your end.
However, if you notice the EntityManager not being created with the necessary directories, simply run the command:
apex scan-classes
The above command will go through all files within the /src/ directory and compile a list of all entity directories among other things. This will resolve the issue of missing entity directories.
Creating Entity Classes
Assuming you already have your SQL database tables created, you can easily generate Doctrine entiy classes for them by simply including the --doctrine
flag within the CLI command to create a model, for example:
apex opus model MyPackage/Models/Order --dbtable orders --doctrine
With the --doctrine
flag present, a Doctrine entity class will be generated instead of an Apex model class. As per-usual, it will also take into account column type, primary key, unique, nullable, forieng key constraints, et al.
Migrations
Much the same as models, you can also create Doctrine migrations by simply including the --doctrine
flag within the standard CLI command, for example:
apex migration create demo --doctrine
You may also include the --dump
and --diff
flags for their respective functions. For example to dump the entire SQL database schema you would use the command:
apex migration create demo --doctrine --dump
The same works for the --diff
flag except simply replace it with --dump
in the above command.