首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >教条OneToOne让我发疯

教条OneToOne让我发疯
EN

Stack Overflow用户
提问于 2015-08-21 16:02:20
回答 3查看 197关注 0票数 1

我知道这是一个反复出现的问题,但在创建了两个实体之间的OneToOne关系并运行'php应用程序/控制台原则:schema: after‘之后,我得到了这个错误:

代码语言:javascript
复制
'[Mapping]  FAIL - The entity-class 'HO\CisBundle\Entity\AffiliateSalesAccounts' mapping is invalid:
* The association HO\CisBundle\Entity\AffiliateSalesAccounts#affiliate refers to the inverse side field HO\HasoffersBundle\Entity\Affiliate#affiliateSalesAccounts which does not exist.'

这是这两个实体的代码的一部分:

AffiliatesSalesAccount实体

代码语言:javascript
复制
namespace HO\CisBundle\Entity;

use HO\HasoffersBundle\Entity\Affiliate;
use Doctrine\ORM\Mapping as ORM;

/**
 *
 * @ORM\Table(name="AffiliateSalesAccounts")
 * @ORM\Entity()
 * @ORM\HasLifecycleCallbacks
 */
class AffiliateSalesAccounts {

    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     *
     */
    private $id;

    /**
     * @var \HO\HasoffersBundle\Entity\Affiliate
     *
     * @ORM\OneToOne(targetEntity="HO\HasoffersBundle\Entity\Affiliate", inversedBy="affiliateSalesAccounts")
     * @ORM\JoinColumn(name="affiliate_id", referencedColumnName="id")
     *
     */
    private $affiliate;

    ...

    /**
     * @param Affiliate $affiliate
     */
    public function setAffiliate(Affiliate $affiliate)
    {
        $this->affiliate = $affiliate;
    }

    /**
     * @return Affiliate
     */
    public function getAffiliate()
    {
        return $this->affiliate;
    }
}

附属实体

代码语言:javascript
复制
namespace HO\HasoffersBundle\Entity;

use HO\CisBundle\Entity\AffiliateSalesAccounts;
use Doctrine\ORM\Mapping as ORM;

/**
 *
 * @ORM\Table(name="ho_Affiliate")
 */
class Affiliate
{


    /**
     * @var AffiliateSalesAccounts
     *
     * @ORM\OneToOne(targetEntity="HO\CisBundle\Entity\AffiliateSalesAccounts", mappedBy="affiliate")
     */
    private $affiliateSalesAccounts;


    ....

    /**
     * @param \HO\CisBundle\Entity\AffiliateSalesAccounts $affiliateSalesAccounts
     */
    public function setAffiliateSalesAccounts($affiliateSalesAccounts)
    {
        $this->affiliateSalesAccounts = $affiliateSalesAccounts;
    }

    /**
     * @return \HO\CisBundle\Entity\AffiliateSalesAccounts
     */
    public function getAffiliateSalesAccounts()
    {
        return $this->affiliateSalesAccounts;
    }

}

我在两个实体之间还有其他类似的OneToOne关系,它工作得很好。

有人能帮我吗?

非常感谢..。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2015-08-24 08:12:53

好吧,我解决了问题.首先,很抱歉打扰了你,因为这是个愚蠢的愚蠢的心不在焉.由于我们使用Redis缓存理论(与sncRedisBundle),特别是元数据和查询,从属实体缓存在Redis中,但没有新的字段声明"affiliateSalesAccounts“。删除存储附属实体的密钥后,问题得到了解决。

非常感谢你的评论

票数 0
EN

Stack Overflow用户

发布于 2015-08-21 17:43:23

我不确定你的问题,但我注意到我是用不同的方式做的,我只是让这里的代码,这样你就可以检查它了。

代码语言:javascript
复制
/**
 * @ORM\OneToOne(targetEntity="Profile", mappedBy="user", cascade={"remove"})
 **/
private $profile;

另一班:

代码语言:javascript
复制
/**
 * @var \Lifecrops\LCUserBundle\Entity\User
 *
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="NONE")
 * @ORM\OneToOne(targetEntity="Lifecrops\LCUserBundle\Entity\User", inversedBy="profile")
 * @ORM\JoinColumns({
 *   @ORM\JoinColumn(name="User_id", referencedColumnName="id")
 * })
 */
private $user;
票数 0
EN

Stack Overflow用户

发布于 2015-08-21 17:43:33

通常我会做这样的事情:

代码语言:javascript
复制
namespace HO\CisBundle\Entity;

use HO\HasoffersBundle\Entity\Affiliate;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Table(name="AffiliateSalesAccounts")
 * @ORM\Entity()
 */
class AffiliateSalesAccounts {

    /**
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     *
     */
    private $id;

    /**
     * @ORM\OneToOne(targetEntity="Affiliate", inversedBy="affiliateSalesAccounts")
     * @ORM\JoinColumn(name="affiliate_id", referencedColumnName="id")
     *
     */
    private $affiliate;

    /**
     * @param Affiliate $affiliate
     */
    public function setAffiliate(Affiliate $affiliate)
    {
        $this->affiliate = $affiliate;
    }

    /**
     * @return Affiliate
     */
    public function getAffiliate()
    {
        return $this->affiliate;
    }
}

第二个实体:

代码语言:javascript
复制
namespace HO\HasoffersBundle\Entity;

use HO\CisBundle\Entity\AffiliateSalesAccounts;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Table(name="ho_Affiliate")
 * @ORM\Entity()
 */
class Affiliate
{


    /**
     * @ORM\OneToOne(targetEntity="AffiliateSalesAccounts", mappedBy="affiliate")
     */
    private $affiliateSalesAccounts;

    /**
     * @param AffiliateSalesAccounts $affiliateSalesAccounts
     */
    public function setAffiliateSalesAccounts($affiliateSalesAccounts)
    {
        $this->affiliateSalesAccounts = $affiliateSalesAccounts;
    }

    /**
     * @return AffiliateSalesAccounts
     */
    public function getAffiliateSalesAccounts()
    {
        return $this->affiliateSalesAccounts;
    }

}

清除缓存是重要的部分,如果一切都变坏了,您可以查看:

代码语言:javascript
复制
doctrine:
  orm:
    auto_mapping: true
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32144767

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档