Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding more options for Single Table Inheritance in Doctrine 2 Annotation #143

Closed
wants to merge 2 commits into from

Conversation

molaux
Copy link
Contributor

@molaux molaux commented Jun 17, 2015

Hello,
here is my attempt to make Single Inheritance more customizable.
I had to make possible to force generation of array keys in MwbExporter/Object/Annotation.php in order to be able to specify integer discrimanator values. When defining php array keys as string representation of integer, php interprets those as integer, then Annotation::isKeysNumeric is not suficient to determine wether or not to write these keys. In this case (and when discriminator is an integer), discriminatorMap Annotation was not able to write keys, as specified by user. Not sure it was the best way to achieve this.

@molaux molaux changed the title Adding more options for Single Table Inheritance in Doactrine 2 Annotation Adding more options for Single Table Inheritance in Doctrine 2 Annotation Jun 17, 2015
@molaux
Copy link
Contributor Author

molaux commented Jul 28, 2015

After further reading, I'm figuring out that it may be possible to make it entirely though single table inheritance (it seems I misunderstood the «SINGLE» word in thinking that hierarchy tree could only have a unique parent entity) :

BasePerson (@entity, @InheritanceType("SINGLE_TABLE"), @DiscriminatorMap({"base_person" = "BasePerson", "person" = "Person", "base_man" = "BaseMan", "man" = "Man", "base_woman" = "BaseWoman", "woman" = "Woman"}))
Person extends BasePerson (@entity)
BaseMan extends Person (@entity) - BaseWoman extends Person (@entity)
Man extends BaseMan (@entity) - Woman extends BaseWoman (@entity)

Maybe it should be more suitable and simple ?

@malutanpetronel
Copy link

how the annotation in the comment table should look in the BasePerson in order to obtain the
BasePerson (@entity, @InheritanceType("SINGLE_TABLE"), @DiscriminatorMap({"base_person" = "BasePerson", "person" = "Person", "base_man" = "BaseMan", "man" = "Man", "base_woman" = "BaseWoman", "woman" = "Woman"})) ? Can you please share it ?

@molaux molaux force-pushed the master branch 2 times, most recently from e567230 to 34f4f83 Compare December 7, 2015 07:36
@molaux
Copy link
Contributor Author

molaux commented Dec 29, 2015

6 months later, I commited and rebased my enhancements to handle single inheritance while benefits from "base" classes. I added in the same time some functionalities I was needing while developping and testing.
See example/data/inheritance.mwb for the example. The extraction of resulting code can be found on a branch of mine (https://github.com/molaux/mysql-workbench-schema-exporter/blob/test-inheritance/test) in the test folder. Have a look at the config file mwb-exporter.test.json
Notes :

  • I had to make directories more customizable and so added the possibility to manage different directories for Entities, Ropositories and BaseEntities. For that purpose, the "dir" main config points now to the target bundle base directory (instead of entities one) : subdirectories for Entities, Ropositories and BaseEntities are now deduced from subnamespaces in configuration (entityNamespace, repositoryNamespace and baseEntityNamespace). With a lot of tables, it's much comfortable.
  • I also made base classes abstract as they should not exist in database. In the same idea, it's not referenced in discriminator map as 'base' anymore
  • I added few configuration options like overwriteExtendedEntities or generateSingleInheritance (this one generates a singleton discrimanator map even if there is no discriminator map in table comment and no extendable entity is configured) that are not yet documented
  • the default main entity discriminator is "extended" (to stay backward compatible) if not supplied through comment and if discriminator type is string
  • getters and setters involves now BaseEntities whereas doctrine annotations (relations, etc...) use leaves (Entities)
  • I did my best to follow conventions. Tell me if I'm still wrong.

To do:

  • Abstract "base" classes being not referenced in discriminator map anymore, it should be checked if single inheritance is still needed to achieve extendableEntities mode when no single inheritance is expected;
  • in my example, I tested adding getters and setters to Violonist and Violon child entity to see if it works as expected. In a next session I plan to generate it directly in Violonist and Violon base class by simply configuring foreign key comment in MWB;
  • at present time, single inheritance generates only a one level deep tree where leaves are all descedent from main entity. It would be great to be able to describe a more complexe tree through the table dicriminator comment; It is not a very hard work.

@molaux
Copy link
Contributor Author

molaux commented Dec 29, 2015

@malutanpetronel, sorry to answer your question so late but I had to finish this before, and so much other things even before. Have a look at my example (particularly, the comments on Tools, Persons, and Skills) and the README.md file.

@malutanpetronel
Copy link

thx... no hurry :) anytime an answer is good ;)

@molaux
Copy link
Contributor Author

molaux commented Jan 11, 2016

The recent project refactor makes my pull request obsolete. No idea on how to maintain this...

@molaux molaux closed this Jan 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants