gpt4 book ai didi

doctrine-orm - FOSUserBundle 和 FOSFacebookBundle : userManager->updateUser() : "unknown error" (it is a doctrine error)

转载 作者:行者123 更新时间:2023-12-01 04:08:11 25 4
gpt4 key购买 nike

FOSUserBundle 对我正在从事的项目很有用。但我正在尝试嵌入 FOSFacebookBundle 并使其与 一起使用FOSUserBundle .

为此,我建立了自己的 Acme\MyBundle\Entity\User.php除了提供 UserBundle 的内容之外,还添加了一些我想从 Facebook 存储的字段。这
这个类的代码已经过调试并且可以工作(嗯……这就是我的想法!见下文)。

不起作用的是(在我的 Acme\MyBundle\Security\User\Provider\FacebookProvider.php 中,在 loadUserByUsername() 中)这一行:

        $this->userManager->updateUser($user);
Acme\MyBundle\Security\User\Provider\FacebookProvider.php与文档( read it here )相同

以下元素是 print_r($user); 的输出就在之前
执行 $this->userManager->updateUser($user); :
Acme\MyBundle\Entity\User Object(    [id:protected] =>    [facebookID:protected] => 847000001    [first_name:protected] => Peter    [middle_name:protected] =>    [last_name:protected] => Parker    [fullname:protected] => Peter Parker    [locale:protected] => en_US    [timezone:protected] => 2    [updated_time:protected] => 2011-10-27T17:13:24+0000    [birthday:protected] => DateTime Object        (            [date] => 1961-07-01 10:31:53            [timezone_type] => 3            [timezone] => Europe/Berlin        )    [languages:protected] => Doctrine\Common\Collections\ArrayCollection Object        (        [_elements:Doctrine\Common\Collections\ArrayCollection:private] => Array            (        [0] => Acme\MyBundle\Entity\SpokenLanguage Object            (            [facebookID:Acme\MyBundle\Entity\SpokenLanguage:private] => 113051505375958            [name:Acme\MyBundle\Entity\SpokenLanguage:private] => Italien            )        [1] => Acme\MyBundle\Entity\SpokenLanguage Object            (            [facebookID:Acme\MyBundle\Entity\SpokenLanguage:private] => 112264595467201            [name:Acme\MyBundle\Entity\SpokenLanguage:private] => Français            )        [2] => Acme\MyBundle\Entity\SpokenLanguage Object            (            [facebookID:Acme\MyBundle\Entity\SpokenLanguage:private] => 103803232991647            [name:Acme\MyBundle\Entity\SpokenLanguage:private] => English            )        )    )    [usernameFB:protected] => spiderman    [username:protected] => Peter Parker    [usernameCanonical:protected] =>    [email:protected] => peterparker@marvel.com    [emailCanonical:protected] =>    [enabled:protected] => 1    [algorithm:protected] =>    [salt:protected] =>    [password:protected] =>    [plainPassword:protected] =>    [lastLogin:protected] =>    [confirmationToken:protected] => 540grdgfg343004g8g0skg0wg408k    [passwordRequestedAt:protected] =>    [groups:protected] =>    [locked:protected] =>    [expired:protected] =>    [expiresAt:protected] =>    [roles:protected] => Array        (            [0] => ROLE_FACEBOOK        )    [credentialsExpired:protected] =>    [credentialsExpireAt:protected] =>)

The message error is "UNKNOWN ERROR". So I decided to go to look Where this message is sent in the Bundle. And I've found that it was set in an Exception. I decided to output the Exception Message.

So below the Exception message:

A new entity was found through the relationship 'Acme\MyBundle\Entity\User#languages' that was not configured to cascade persist operations for entity: Acme\MyBundle\Entity\SpokenLanguage@000000004a9e2dfa0000000001482b74. Explicitly persist the new entity or configure cascading persist operations on the relationship. If you cannot find out which entity causes the problem implement 'Acme\MyBundle\Entity\SpokenLanguage#__toString()' to get a clue.

So I guess I have not well-coded the Doctrine Annotations of my User class and the problem is the ManyToMany() association mapping.

Here the Annotations of the field $languages in my Acme\MyBundle\Entity\User.php:

/**
* @var \Doctrine\Common\Collections\ArrayCollection
* @ORM\ManyToMany(targetEntity="SpokenLanguage")
* @ORM\JoinTable(name="users_spokenlanguage",
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="spokenlanguage_id", referencedColumnName="facebookID")}
* )
*/
protected $languages;

你们有什么想法如何解决这个问题吗?
我在考虑一个级联问题。

谢谢大家。

最佳答案

好的!我终于解决了这个!

您必须添加参数 cascade={'persist','remove','merge'}到注解 ManyToMany。

像这样:

@ORM\ManyToMany(targetEntity="SpokenLanguage", cascade={"persist", "remove", "merge"})

关于doctrine-orm - FOSUserBundle 和 FOSFacebookBundle : userManager->updateUser() : "unknown error" (it is a doctrine error),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7930317/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com