0

Would like to know what's the best way to map entities in another directory using YAML. I've a tree structre like the one below:

| src
|----User
|--------Domain
|------------Entity
|----------------User.php
|--------Infrastructure
|------------Resources
|----------------config
|--------------------doctrine
|-------------------------User.orm.yml

My doctrine config file, looks like this one:

parameters:
    env(DATABASE_URL): ''

doctrine:
    dbal:
        # configure these for your database server
        driver: 'pdo_mysql'
        server_version: '5.7'
        charset: utf8mb4
        default_table_options:
            charset: utf8mb4
            collate: utf8mb4_unicode_ci
        url: '%env(resolve:DATABASE_URL)%'

    orm:
        auto_generate_proxy_classes: '%kernel.debug%'
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true
        mappings:
            User:
                is_bundle: false
                type: yml
                dir: '%kernel.project_dir%/src/User/Infrastructure/Resources/config/doctrine'
                prefix: 'App\User\Domain\Entity'
                alias: User

And the User.orm.yml mapping file:

App\User\Domain\Entity\User:
    type: entity
    table: users
    repositoryClass: App\User\Infrastructure\Persistance\Doctrine\DoctrineUserRepository
    id:
        id:
            type: integer
            generator:
                strategy: AUTO
    fields:
        password:
            type: string
            length: 64
            nullable: false
        email:
            type: string
            length: 255
            unique: true
            nullable: false

When I try to migrate schema by typing: bin/console doctrine:schema:update --force. Leads to the message:

[OK] No Metadata Classes to process.

Am I doing wrong for this?

Thanks!

Filip
  • 143
  • 12
  • auto_mapping: false to start since you are providing the mapping info manually. Not sure if that will fix it. The alias should be App though that is not the cause of the problem. – Cerad Jul 21 '18 at 12:28
  • Did you clear the cache `rm -rf var/cache/*` ? Always call `doc:sch:val` first to validate the schema. `doc:map:info` also helps. Side note here, your `unique` index [won't work](https://stackoverflow.com/questions/6172798/mysql-varchar255-utf8-is-too-long-for-key-but-max-length-is-1000-bytes) on `varchar(255)` with `utf8mb4` (the `email` property). Switch to `xml` by the way. phpStorm will especially like this since it will validate the syntax as you write it. – Mike Doe Jul 21 '18 at 12:35
  • I did a quick test and your posted info works regardless of the value of auto_mapping. "bin/console doctrine:mapping:info" is probably the easiest way to test. All I can suggest is that you triple check your spellings. I might add that Doctrine Entities are not Domain Entities. Your directory structure may not end up as clean as you might like. – Cerad Jul 21 '18 at 12:51
  • @Cerad did the mapping file worked with the `.yml` extension in your test? – gp_sflover Jul 21 '18 at 13:11
  • @gp_sflover Yes it did. In fact it required yml. Doctrine does not recognize yaml for mapping files. Possible because yaml mapping is going away in D3. The single quotes don't hurt. – Cerad Jul 21 '18 at 14:40
  • Thanks @Cerad. I've already abandoned yml for xml months ago (_due to the changes in D3_) and I remembered badly about mapping file extension :-) – gp_sflover Jul 21 '18 at 16:10

0 Answers0