【发布时间】:2019-01-24 13:45:06
【问题描述】:
我在奏鸣曲中跟随this documentation,一步一步地成功了。 然后我添加了一个新实体并尝试生成与用户实体的多对多关系,当我验证它时返回此错误
$ bin/console doctrine:schema:validate
Mapping
-------
[FAIL] The entity-class AppBundle\Entity\Business mapping is invalid:
* The association AppBundle\Entity\Business#user refers to the owning side field Application\Sonata\UserBundle\Entity\User#business which does not exist.
Database
--------
[OK] The database schema is in sync with the mapping files.
这是我的两个实体
命名空间 AppBundle\Entity;
使用 Doctrine\ORM\Mapping 作为 ORM; 使用 Gedmo\Mapping\Annotation 作为 Gedmo;
/**
* Business
*
* @ORM\Table(name="business")
* @ORM\Entity(repositoryClass="AppBundle\Repository\BusinessRepository")
*/
class Business
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="BusinessName", type="string", length=255)
*/
private $businessName;
/**
* @var string
*
* @ORM\Column(name="fantasyName", type="string", length=255)
*/
private $fantasyName;
/**
* @var string
*
* @ORM\Column(name="cuit", type="string", length=13)
*/
private $cuit;
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\BankAccountType", inversedBy="business")
*/
private $bankAccountType;
/**
* @var \DateTime $created
*
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime")
*/
private $created;
/**
* @var \DateTime $updated
*
* @Gedmo\Timestampable(on="update")
* @ORM\Column(type="datetime")
*/
private $updated;
/**
* @ORM\ManyToMany(targetEntity="\Application\Sonata\UserBundle\Entity\User", mappedBy="business")
*/
private $user;
/**
* @var bool
*
* @ORM\Column(name="isActive", type="boolean")
*/
private $isActive = true;
还有这个
namespace Application\Sonata\UserBundle\Entity;
use Sonata\UserBundle\Entity\BaseUser as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* This file has been generated by the SonataEasyExtendsBundle.
*
* @link https://sonata-project.org/easy-extends
*
* References:
* @link http://www.doctrine-project.org/projects/orm/2.0/docs/reference/working-with-objects/en
*/
class User extends BaseUser
{
/**
* @var int $id
*/
protected $id;
/**
* @ORM\ManyToMany(targetEntity="\AppBundle\Entity\Business", inversedBy="user")
* @ORM\JoinTable(name="business_user")
*/
private $business;
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
$this->business = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Get id.
*
* @return int $id
*/
public function getId()
{
return $this->id;
}
}
有什么想法吗?
【问题讨论】:
-
能否分享一下你的整个实体类
-
这是没有getter和setter的整个实体
-
但它在您的业务实体中包含构造函数
标签: symfony orm fosuserbundle relation sonata