【发布时间】:2017-01-06 18:16:51
【问题描述】:
我正在使用 Symfony 3.1 中名为 Profile 和 Blog 的两个实体。这里这两个实体构成了一对多的关系。一个 Profile 可以创建多个 Blog ,除了一个 Blog 属于一个 Profile 。因此,要从Blog 访问个人资料信息,我想在blog table 中创建一个foreign key。我已经在我的代码中做到了,但主要问题是当我写这个命令时——$ php bin/console doctrine:schema:update --dump-sql,它显示
“无需更新 - 您的数据库已与当前实体元数据同步”。任何人都可以帮助我...这里我提供我完成的两个类...
//Profile.php
<?php class Profile { /** * @var int */ private $id; /** * @var string * */ private $userName; /** * @var string * */ private $email; /** * @ORM\Column(name="url", type="string") */ private $url; /** * Get id * * @return int */ public function getId() { return $this->id; } /** * Set userName * * @param string $userName * * @return Profile */ public function setUserName($userName) { $this->userName = $userName; return $this; } /** * Get userName * * @return string */ public function getUserName() { return $this->userName; } /** * Set email * * @param string $email * * @return Profile */ public function setEmail($email) { $this->email = $email; return $this; } /** * Get email * * @return string */ public function getEmail() { return $this->email; } }
博客.php
类博客 { /** * @var 整数 */ 私人 $id;
/** * @var string */ private $blogTitle; /** * @var string */ private $blogContent; /** * * >@ORM\ManyToOne(targetEntity="AppBundle\Entity\Profile",inversedBy="blogs") * @ORM\JoinColumn(name="profile_id", referencedColumnName="id") * */ private $product_id; /** * Get id * * @return int */ public function getId() { return $this->id; } /** * Set blogTitle * * @param string $blogTitle * * @return Blog */ public function setBlogTitle($blogTitle) { $this->blogTitle = $blogTitle; return $this; } /** * Get blogTitle * * @return string */ public function getBlogTitle() { return $this->blogTitle; } /** * Set blogContent * * @param string $blogContent * * @return Blog */ public function setBlogContent($blogContent) { $this->blogContent = $blogContent; return $this; } /** * Get blogContent * * @return string */ public function getBlogContent() { return $this->blogContent; } /** * @return Profile */ public function getprofileId() { return $this->profile_id; } /** * @param Profile $profile_id */ public function setProfileId(Profile $profile _id) { $this->profile_id = $profile_id; }}
【问题讨论】:
-
我认为,您忘记了实体的
@ORM\Entity()注释。试试this link。这是entity example的要点。 -
我已经尝试过了,但没有别的...
标签: php symfony orm doctrine-orm