laravel-doctrine / extensions

Extensions integration for Doctrine2 and Laravel
http://laraveldoctrine.org/
MIT License
48 stars 24 forks source link

Translatable Extension doesn't work with YAML mapping driver #46

Open DarkWasabi opened 4 years ago

DarkWasabi commented 4 years ago

I use simplified_yaml mapping driver in my app and want to add multi-language support. So after enabling translatable extension doctrine throws exception:

{
    exception: "Doctrine\Common\Persistence\Mapping\MappingException"
    file: "/var/www/vendor/doctrine/persistence/lib/Doctrine/Common/Persistence/Mapping/MappingException.php"
    line: 64
    message: "No mapping file found named 'Translation.orm.yml' for class 'Gedmo\Translatable\Entity\Translation'."
}

It seems that extension works properly only with annotation driver. In Symfony you can specify driver for extension. If it's possible with Laravel it probably should be documented

Here is my doctrine.php

'managers'                   => [
        'default' => [
            'dev'           => env('APP_DEBUG', false),
            'meta'          => env('DOCTRINE_METADATA', 'annotations'),
            'connection'    => env('DB_CONNECTION', 'mysql'),
            'namespaces'    => [
                'App\Entities'
            ],
            'paths'         => [
                config_path('orm') => 'App\Entities'           ],
            'repository'    => App\Core\ORM\EntityRepository::class,
            'proxies'       => [
                'namespace'     => false,
                'path'          => storage_path('proxies'),
                'auto_generate' => env('DOCTRINE_PROXY_AUTOGENERATE', false)
            ],
            /*
            |--------------------------------------------------------------------------
            | Doctrine events
            |--------------------------------------------------------------------------
            |
            | The listener array expects the key to be a Doctrine event
            | e.g. Doctrine\ORM\Events::onFlush
            |
            */
            'events'        => [
                'listeners'   => [],
                'subscribers' => []
            ],
            'filters'       => [],
            /*
            |--------------------------------------------------------------------------
            | Doctrine mapping types
            |--------------------------------------------------------------------------
            |
            | Link a Database Type to a Local Doctrine Type
            |
            | Using 'enum' => 'string' is the same of:
            | $doctrineManager->extendAll(function (\Doctrine\ORM\Configuration $configuration,
            |         \Doctrine\DBAL\Connection $connection,
            |         \Doctrine\Common\EventManager $eventManager) {
            |     $connection->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
            | });
            |
            | References:
            | http://doctrine-orm.readthedocs.org/en/latest/cookbook/custom-mapping-types.html
            | http://doctrine-dbal.readthedocs.org/en/latest/reference/types.html#custom-mapping-types
            | http://doctrine-orm.readthedocs.org/en/latest/cookbook/advanced-field-value-conversion-using-custom-mapping-types.html
            | http://doctrine-orm.readthedocs.org/en/latest/reference/basic-mapping.html#reference-mapping-types
            | http://symfony.com/doc/current/cookbook/doctrine/dbal.html#registering-custom-mapping-types-in-the-schematool
            |--------------------------------------------------------------------------
            */
            'mapping_types' => [
                //'enum' => 'string'
            ]
        ]
    ],

Here is my Category.orm.yml

App\Entities\Category:
  type: entity
  table: categories
  repositoryClass: App\Repositories\CategoryRepository

  gedmo:
    translation:
      locale: locale
    tree:
      type: nested

  id:
    id:
      type: integer
      id: true
      generator:
        strategy: IDENTITY

  fields:
    name:
      type: string
      nullable: false
      gedmo:
        - sluggable
        - translatable

    description:
      type: text
      nullable: true
      gedmo:
        - translatable

    slug:
      type: string
      gedmo:
        slug:
          separator: '-'
          style: lower
          fields:
            - name

    left:
      type: integer
      column: lft
      gedmo:
        - treeLeft

    right:
      type: integer
      column: rgt
      gedmo:
        - treeRight

    level:
      type: integer
      column: lvl
      gedmo:
        - treeLevel