I'm using this official tutorial to generate entityies from database, all works well except db column comments they are totally missing.
When i run this mapping import command in xml i see column comment
php bin/console doctrine:mapping:import --force AcmeBlogBundle xml
right after running
php bin/console doctrine:mapping:convert annotation ./src
when i open Entity/SomeTable.php some_column (which had comment in database) dose not have options={"comment":"some comment"} in annotation
So do i miss some option for convert command or it is bug of doctrine/symfony and is there a solution for this ?
Note: i have tested this with both symfony2 and symfony3 issue is same
Currently there is no option that will convert your comments and add it to the entity class. The Entity geneartion can be seen in the DoctrineBundle of Symfony in the class Doctrine\ORM\Tools\EntityGenerator this class says it all:
Generic class used to generate PHP5 entity classes from ClassMetadataInfo instances.
So in easy words the mapping you create in xml is then read as ClassMetadataInfo and the EntityGenerator generates the entity class from that ClassMetadataInfo. If you want you can try to add an implementation for the comment or propose a PR or bug in the symfony git repository.
See generateFieldMappingPropertyDocBlock method of the Doctrine\ORM\Tools\EntityGenerator class and see if you can manage to understand the code and add your comment from there.
Based on #SimeonKolev answer i was able to implement simple fix for this issue in doctrine/orm/lib/Doctrine/ORM/Tools/EntityGenerator.php to have options={"comment"=".."} filled in each Entity
Solution was add in EntityGenerator.php method generateFieldMappingPropertyDocBlock before if (isset($fieldMapping['unsigned']) ... condition near to ~1652 line
if( isset($fieldMapping['options']) && is_array($fieldMapping['options'])
&& isset($fieldMapping['options']['comment']) ){
$column[] = 'options={"comment"="'.$fieldMapping['options']['comment'].'"}';
}
Related
I am trying to use the Doctrine Scheme tool with ZF2 without much success, I am trying to update my Mysql DB via command line but I keep getting this error:
$ ./doctrine-module orm:schema-tool:create --dump-sql [Doctrine\DBAL\Schema\SchemaException] The
table with name 'ondemand_server.rbu_roles' already exists.
The rbu_roles is from ZfcRbac and I would imagine it is defined in the vendor module as well as in my own custom modules, how do I deal with this? Is there a way to ignore certain entities etc?
Cheers!
Check your entity annotations, if you have done some copy/paste, you might have a duplication of the table name:
#ORM\Table(name="rbu_roles")
I was looking for a built-in method to urlize/slugify a string, instead of copying a strandard one found on google.
Thus I found this : http://sourcecookbook.com/en/recipes/59/call-the-slugify-urlize-function-from-doctrine , referencing to this Doctrine Class http://www.tig12.net/downloads/apidocs/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Doctrine_Inflector.class.html , with the method urlize() which is exactly what I'm looking for.
But, in my Doctrine Bundle from Symfony 2, in \vendor\doctrine\common\lib\Doctrine\Common\Util my Inflector class is pretty empty.
What happened to this urlize() method ? Do I have to recode it ?
There's https://github.com/Behat/Transliterator which includes the urlize function from Doctrine1
This is the part taken from Doctrine 1.2.3
Doctrine inflector has static methods for inflecting text
You could just composer require behat/transliterator
and have a HelperClass extending Behat\Transliterator.
And then be able to do: MyStringHelper::urlize("isn't that great?")
The file you are looking at (Doctrine\Common\Util\Inflector) is supposed to be used internally by Doctrine, to convert between table names (underscore separated), property names (camelCase), and class names (CamelCase).
What you are looking for can be achieved with the sluggable doctrine extension. You can ingtegrate it easily into a symfony2 application with stof/StofDoctrineExtensionsBundle.
I want to use doctrine migrations in my non-symfony project, so I got the phar standalone from https://github.com/doctrine/migrations. I configured everything properly (db-configuration and configuration) and then when doing "migrations:status" I get the error:
[Doctrine\DBAL\DBALException]
Unknown database type enum requested,
Doctrine\DBAL\Platforms\MySqlPlatform may not support it.
Now there are many resources on how to fix this in the context of a symfony app (for instance http://wildlyinaccurate.com/doctrine-2-resolving-unknown-database-type-enum-requested) but where can I put this type mapping in this case? Should I extract the .phar, put the code in it (where?) and then re-package it? (how?)
I have tried something for Zend framework and it worked:
Open ./vendor/doctrine/dbal/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
Search for function initializeDoctrineTypeMappings()
create an entry for enum as,
'enum' => 'string'
Worked like charm !
That problem resolved in this fork
https://github.com/dyadyavasya/migrations
By default Doctrine does not map the MySQL enum type to a Doctrine type. This is because Enums contain state (their allowed values) and Doctrine types don’t.
Use fork at link and you can register MySQL ENUMs to map to Doctrine strings.
This way Doctrine always resolves ENUMs to Doctrine strings.
migrations.yml
name: Doctrine Sandbox Migrations
migrations_namespace: DoctrineMigrations
table_name: doctrine_migration_versions
migrations_directory: /path/to/migrations/classes/DoctrineMigrations
mapping_types:
enum: string
More information - https://github.com/dyadyavasya/migrations#migrationsyml
What Ocramius said:
You need to use migrations and setup the CLI on your own. Start from cloning github.com/doctrine/migrations and installing via composer. After that, customize your CLI runner to setup the connection according to your own needs.
is there any way to tell doctrine automaticaly create schema tables without using this command :
doctrine:schema:update --force
Using SchemaTool and EntityManager you can do this:
$schemaTool = new \Doctrine\ORM\Tools\SchemaTool($entityManager);
$classes = $entityManager->getMetadataFactory()->getAllMetadata();
$schemaTool->createSchema($classes);
I'm not sure what you want to do, but if you want to do it from php code, you can check how the doctrine command works and copy the code. You can find it here:
vendor/symfony/src/Symfony/Bundle/DoctrineBundle/Command/CreateDatabaseDoctrineCommand.php
If you check the execute method, you will see how it's done. Apparently you need to get a connection through the DBAL DriverManager, which gives you access to a schema object, which in turn has a createDatabase method. I have not tried this myself.
Is it possible to use SubSonic 3's Simple Repository with non-plural table names? My DB already exists, the table names a re singular add I cannot change them.
Nope, it is hardcoded in the SubSonic's source. You can pull it down and trace the migration steps to see where the plural happens. I know, cause I wanted the same thing.
I was tinkering with modifying the source to make plurals optional via some parameter/config override or alike. But, I didn't get it completed (yet).
If your tables already exist then this is not the intended use of the Simple Repository model. The simple repository model is designed to generate the table structures for you using migrations.
If you are using a database that already exists then you would be better served using the T4 Templates as they also support the relationships between your tables.
Cheers,
Ed
With Subsonic 3.0.0.4 in the settings.ttinclude I removed the line;
AddSingularRule("s$", String.Empty);
which was down about 260 lines in the Inflector rules class. Didn't need to mess around with the subsonic source code.
HTH