https://github.com/leongersen/entity-generator
Database-first Doctrine entity generator with oneToMany and manyToOne support
https://github.com/leongersen/entity-generator
doctrine doctrine-orm entity php7
Last synced: 4 months ago
JSON representation
Database-first Doctrine entity generator with oneToMany and manyToOne support
- Host: GitHub
- URL: https://github.com/leongersen/entity-generator
- Owner: leongersen
- License: mit
- Created: 2020-01-04T08:43:40.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-11-06T20:39:06.000Z (over 1 year ago)
- Last Synced: 2025-04-05T11:11:09.856Z (10 months ago)
- Topics: doctrine, doctrine-orm, entity, php7
- Language: PHP
- Size: 31.3 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Entity Generator
The Doctrine Project [will be removing support for generating entities](https://github.com/symfony/symfony-docs/issues/8893) in Doctrine 3.
Not all development workflows will fit the proposed entity-first database management strategy.
To keep supporting a database-first workflow this project implements an alternative database oriented entity generator.
## Features
- Generate entities with type annotations, getters, setters, adders and removers;
- Supports `oneToMany` and `manyToOne` relationships, including pluralization of properties and methods.
## License
This project is licensed [MIT](https://choosealicense.com/licenses/mit/) and can be used for free in any personal or commercial project.
## Usage
```shell script
bin/entity-generator entity-generator:generate
```
### Options
- `dsn` Accepts the same format as Doctrine, so the value configured in `.env` can be used
- `namespace` Namespace for the generated entities (Default `App\Entity`)
- `directory` Output directory for the generated entities (Default `src/Entity`)
- `collection-interface` Interface name for the collection type to use in the generated entities (Default `\Doctrine\Common\Collections\Collection`)
- `collection-implementation` (Default `\Doctrine\Common\Collections\ArrayCollection`)
### Using a DSN from a .env file
```shell script
source .env
bin/entity-generator entity-generator:generate --dsn $DATABASE_URL
```
## Implementation
- A mapping is generated from an existing database using `SHOW CREATE TABLE`.
- Entity classes are rendered using a Twig template.
## Limitations
- Only provides a `\PDO` based driver and an mapper for `MySQL`-like sql dialects.
- Annotations for (unique) indexes are not (yet) implemented
- `ManyToMany` relations are not (yet) supported ([motivation](https://stackoverflow.com/questions/18655286/doctrine-2-how-to-handle-join-tables-with-extra-columns))
- Doctrine Custom types are not supported
## Open issues
- Naming conflicts on `xyx_id` with a foreign key and field `xyx` (both become `xyz`)
- Naming conflicts on multiple foreign keys from one table to another (`xyz.abc_1_id` and `xyz.abc_2_id` both become `xyz.abcs`)
- Blobs are not yet implemented