多个entitymanager symfony

时间:2017-10-18 16:45:30

标签: symfony entitymanager

之前我只使用一个实体管理器与我的数据库进行交互。

一切顺利,直到我添加2个新的实体管理器(一个实体管理器插入数据和一个实体管理器来选择数据)

    -> I want to make a replication of my database later.

我认为,我可以单独解决问题,但我只想了解为什么会出现此错误:

    A new entity was found through the relationship 'AppBundle\Entity\Userinterest#user'
    that was not configured to cascade persist operations for entity: my_username. 
    To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity 
    or configure cascade persist this association in the mapping for example 
    @ManyToOne(..,cascade={"persist"})

我想,我理解问题:):

来自FOSUserBundle的我的用户使用默认实体管理器进行身份验证。

    $userinteret->setUser($this->getUser());
    $em = $this->getDoctrine()->getManager();
    $em->persist($userinteret);
    $em->flush();

然后,我不知道如何存储token_storage。但是因为我使用了token_storage中的用户,我认为探测器来自那里。

1 个答案:

答案 0 :(得分:0)

尝试:

    // All 3 return the "default" entity manager
    $em = $this->getDoctrine()->getManager();
    $em = $this->getDoctrine()->getManager('default');
    $em = $this->get('doctrine.orm.default_entity_manager');

    // Both of these return the "customer" entity manager
    $customerEm = $this->getDoctrine()->getManager('customer');
    $customerEm = $this->get('doctrine.orm.customer_entity_manager');

How to Work with multiple Entity Managers and Connections