Symfony and Doctrine: Default table collation, a better solution

As of symfony 1.4 and if working with doctrine, there are still problem setting default and correct table encoding and collations with symfony doctrine:build task.

I have previously posted 2 solution. The firstĀ involves hacking the core code, which needs to be done with every symfony upgrade. The secondĀ involves adding options to set default encoding and collation in schema.yml, which has to be done on every table! With the latter, tables created by plugins won’t have the correct encoding. You will ended up with a database of tables with mixed collations.

I believe i have found a better solution. add a function to ‘config/ProjectConfiguration.class.php’:

public function configureDoctrine(Doctrine_Manager $manager) {

8 thoughts on “Symfony and Doctrine: Default table collation, a better solution

  1. prettyscripts Reply

    @mario, thanks for your feedback. i was working on a project that requires handling of asian language. at the time my research suggested that utf8_unicode_ci is a better option. however your linked info says that it makes no difference. hmmm….

  2. Nate Michael Reply

    The setting doesn’t have to be per-table. You can add a global setting for every table at the top of your schema.yml file. Like this:

    —- schema.yml
    collate: utf8_general_ci
    charset: utf8
    use_dql_callbacks: true

    Timestampable: ~
    SoftDelete: ~
    first_name: { type: string(32) }
    last_name: { type: string(32) }

  3. ocsi Reply

    That’s a good and easy solution!

    Nate Michael:
    It’s an another option, but, in your case the schema.yml sould contain all the tables from the database. ( And some plugin creates new tables, without the global schema.yml.) So you sould merge these partial schema files. ( or in each file set the charset and collate.)

    Thanks again!

Leave a Reply

Your email address will not be published. Required fields are marked *