Closed nikolaposa closed 4 years ago
I'm afraid I don't have a direct answer for this 😅
I remember there was an issue opened some time ago because of this.
I will have to dig into the issues to remember exactly what was the problem, and then improve the docs, maybe.
Anyway, if everything works for you without adding that, I think you are good 🙂
Yeah, current setup works even without that part, so that's why I was wondering what is the idea behind it, what it was supposed to do. 🤔
If I had to guess, I would say it was related with some of those doctrine commands which generate tables based on entities.
Or maybe it was related with migrations.
It was something in those lines 😅
I will review later today when I get home.
Sounds good, thanks!
@nikolaposa this was the reason to document that https://github.com/acelaya/doctrine-enum-type/issues/23
Ah, interesting, I'll investigate further. But that answers my actual question here so closing this one. Thank you!
I will probably try to provide further details in the docs, maybe even linking to the issue.
I am not sure, but I think registerDoctrineTypeMapping method allows reverse engineering from a db schema to doctrine representation. The method writes an associative array where the first argument is used as key. If my assumption is correct the method instructs doctrine how to translate a db type in a doctrine type. So, as @nikolaposa said, if you call that method twice with an equal value of the first argument, the second time you are just overriding first call. Since it doesn't make sense to translate a varchar to a specific enum, I think the documentation is wrong. I'm still not sure that calling the method is necessary, but possibly the first parameter should be a fictitious one, for example the name of the enumeration.
FWIW, i needed to add this so Doctrine Migrations would work properly. So if anyone ends up here like me trying to fix this for symfony or api-platform, you just need to add some subscriber on migrations events and register your enum types there 👌
There is one bit of documentation that confuses me. :) So in the README it says:
But what does this part actually do? Looking at the Doctrine DBAL code: https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L341, after the above code is executed, only the last enum (
php_enum_gender
) will be mapped toVARCHAR
, right?Ultimately I feel like registering these type mappings is not required in order for things to work properly at the
Type
level which is whatPhpEnumType::registerEnumType()
does.