EkinoWordpressBundle icon indicating copy to clipboard operation
EkinoWordpressBundle copied to clipboard

Accessing Ekino\WordpressBundle\Entity\User from custom entity manager

Open steffi2392 opened this issue 8 years ago • 1 comments

Hi --

I have configured my symfony app to have a custom entity manager for the wordpress side of things and the symfony side of things, as suggested here: https://github.com/ekino/EkinoWordpressBundle/issues/96.

This works well, but now I have a table of objects belonging to a user, and I want to use the user id as a foreign key. Since the Ekino\WordpressBundle\Entity\User entity is managed by a different entity manager, I get the following error when I run php app/console doctrine:schema:update --force --em=symfony

Doctrine\Common\Persistence\Mapping\MappingException]                                                           
The class 'Ekino\WordpressBundle\Entity\User' was not found in the chain configured namespaces AppBundle\Entity

Am I going about this incorrectly? Any advice on the best way to use the user id as a foreign key?

relevant code in my config.yml:

doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                driver: pdo_mysql
                host:     "%database_host%"
                port:     "%database_port%"
                dbname:     "%database_name%"
                user:     "%database_user%"
                password:     "%database_password%"
           symfony:
                driver: pdo_mysql
                host:     "%database_host%"
                port:     "%database_port%"
                dbname:     "%database_name%"
                user:     "%database_user%"
                password:     "%database_password%"
    orm:
        auto_generate_proxy_classes: "%kernel.debug%"           
        default_entity_manager: default
        entity_managers:
            default:
                connection: default
                mappings:
                    EkinoWordpressBundle: ~
            symfony:     
                connection: symfony
                mappings:
                    AppBundle: ~

Relevant code in my doctrine-mapping xml:

<entity name="AppBundle\Entity\Investment" table="investments">
    ...
    <many-to-one
        field="user"
        target-entity="Ekino\WordpressBundle\Entity\User"
        join-column="user">
        <join-column name="user_id" referenced-column-name="ID" />
    </many-to-one>
</entity>

Any guidance would be appreciated. Thanks!

steffi2392 avatar Jun 26 '16 18:06 steffi2392

Update: I can get around this issue a bit by including just the Users entity in my symfony entity manager by moving User.orm.xml and UserMeta.orm.xml to endor/ekino/wordpress-bundle/Resources/config/doctrine/user/ and updating my config.yml to be this:

doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                driver: pdo_mysql
                host:     "%database_host%"
                port:     "%database_port%"
                dbname:     "%database_name%"
                user:     "%database_user%"
                password:     "%database_password%"
           symfony:
                driver: pdo_mysql
                host:     "%database_host%"
                port:     "%database_port%"
                dbname:     "%database_name%"
                user:     "%database_user%"
                password:     "%database_password%"
    orm:
        auto_generate_proxy_classes: "%kernel.debug%"           
        default_entity_manager: default
        entity_managers:
            default:
                connection: default
                mappings:
                    EkinoWordpressBundle: ~
            symfony:     
                connection: symfony
                mappings:
                    AppBundle: ~
                    EkinoWordpressBundle:
                        dir: "Resources/config/doctrine/user"
                        prefix: "Ekino\WordpressBundle\Entity"

Now running the schema update gives me:

[Doctrine\DBAL\Schema\SchemaException]  
There is no column with name 'user_login' on table 'wp_users'.

I feel like I may be approaching this incorrectly. What is the canonical way to use user IDs as foreign keys in this structure?

steffi2392 avatar Jun 26 '16 20:06 steffi2392