简体   繁体   中英

Symfony2 FosUserBundle is not hydrating User Entity with custom Entity

I have my own User Entity which extends the Fos one. It is capable of having another Entity attached to it as a manyToOne relationship.

Using the following code inside my own Profile Controller results in this Entity not being added to the User Entity.

$user = $repo->find($user->getId());

All my other custom fields are in place, its just this Entity that is missing. The relationship looks like this

manyToOne:
    game_system:
        targetEntity: Acme\NameofBundle\Entity\GameSystem
        joinColumn:
            onDelete: SET NULL
            name: game_system_id
            referencedColumnName: id

Edit

It's worth noting that the getGameSystem call works inside my main Bundle, NameofBundle.

But it fails inside of MemberBundle, MemberBundle extends FOSUserBundle. The GameSystem Entity is inside NameofBundle while my User is my MemberBundle.

Edit 2

My config.yml

fos_user:
    db_driver: orm
    firewall_name: main
    user_class: Acme\MemberBundle\Entity\User
    group:
        group_class: Acme\MemberBundle\Entity\User

There seems to be a problem with the line:

$user = $repo->find($user->getId());

which seems redundant How can you id from user if you haven't fetched user from database yet? or, if you have already user object you don't need to get it from database. The following would be more correct and to get the id you want you'd have to make a list with findAll().

$user = $repo->find($id);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM