Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
steffi2392 opened this issue Jun 26, 2016 · 1 comment
Open

Comments

@steffi2392
Copy link

steffi2392 commented Jun 26, 2016

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: #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
Copy link
Author

steffi2392 commented Jun 26, 2016

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant