我有以下关于规则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;
...
...有人能解释为什么会发生这种事吗?
发布于 2013-04-16 23:37:41
对于第一个错误:
在您的User类中,缺少与address相关的属性,因此可能有两种可能性:
protected $user_id:这不起作用,因为Doctrine需要在此位置有一个address对象数组。protected $addresses:您必须将user属性上的Address类中的映射更改为:@ORM\ManyToOne(targetEntity="User", inversedBy="addresses")
对于第二个错误:
在Address类中,您必须删除country上的inversedBy属性:
@ORM\ManyToOne(targetEntity="Country")https://stackoverflow.com/questions/16037394
复制相似问题