我在学说 2 中遇到以下问题,我想将我的地址实体和国家实体加入我的用户实体。因此,经过一些尝试,它在数据库中运行良好,但是当我使用它时,./vendor/bin/doctrine-module orm:validate-schema
它显示映射失败。
[Mapping] FAIL - The entity-class 'User\Entity\Adress' mapping is invalid:
* The association User\Entity\Adress#user refers to the inverse side field User\Entity\User#use
r_id which does not exist.
* The association User\Entity\Adress#country refers to the inverse side field User\Entity\Count
ry#id which is not defined as association.
* The association User\Entity\Adress#country refers to the inverse side field User\Entity\Count
ry#id which does not exist.
我真的不知道为什么会这样,因为我的数据库像这样工作得很好。它识别地址中的用户和国家实体,以及值。
我的用户实体:
...
/**
* Entity Class representing a post of our User module.
*
* @ORM\Table(name="user")
* @ORM\Entity(repositoryClass="User\Repository\UserRepository")
*
* @property int userid
* @property string firstname
* @property string insertion
* @property string lastname
* @property date dateofbirth
* @property string gender
* @property string phonenumber
* @property string mobile
*/
class User extends zfcUser implements UserInterface
{
/**
* Id from user
*
* @ORM\OneToMany(targetEntity="Adress", mappedBy="user", cascade= "remove")
* @access protected
*/
/**
* Firstname of our user
*
* @ORM\Column(type="string", nullable=true)
* @var string
* @access protected
*/
protected $firstname;
...
...
我的地址实体:
/**
* Entity Class representing our Adress module.
*
* @ORM\Entity
* @ORM\Table(name="adress")
* @property integer addressid
* @property string street
* @property integer number
* @property string addition
* @property string zipcode
* @property integer userid
* @property integer countryid
*/
class Adress
{
...
...
/**
* @ORM\ManyToOne(targetEntity="User", inversedBy="user_id")
* @ORM\JoinColumn(name="user_id", referencedColumnName="user_id")
* @var User[]
* @access protected
*/
protected $user;
/**
* @ORM\ManyToOne(targetEntity="Country", inversedBy="id")
* @ORM\JoinColumn(name="country_id", referencedColumnName="id")
* @var Country[]
* @access protected
*/
protected $country;
...
...
我的国家实体:
...
...
/**
* Entity Class representing our Country module.
*
* @ORM\Entity
* @ORM\Table(name="country")
* @property integer id
* @property string countrycode
* @property string countryname
*/
class Country
{
/**
* Id from a country
*
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\OneToMany(targetEntity="Adress", mappedBy="country")
* @var int
* @access protected
*/
protected $id;
...
...
有人解释为什么会这样?