Laravel Doctrine生成模式时无法找到目标实体#

时间:2017-08-09 05:55:54

标签: php laravel laravel-5 doctrine-orm

当我尝试运行php artisan doctrine:schema:create以在发生错误后从实体生成模式。

[Doctrine \ ORM \ Mapping \ MappingException]目标实体App \ Entities \ RankedEntity无法在' App \ Entities \ SongEntity#rank'中找到。

我想在这里做一对多的映射。每个歌曲实体可以映射到许多排名实体。这是两个实体。排名实体:

namespace App\Entities;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="ranks")
 */

class RankEntity
{
    /**
     * @ORM\Id
     * @ORM\ManyToOne(targetEntity="SongEntity", inversedBy="rank")
     * @ORM\JoinColumn(name="rankedSong", referencedColumnName="id")
     */
    private $rankedSong;


    /**
     * @ORM\Id
     * @ORM\ManyToOne(targetEntity="UserEntity")
     */
    private $rankedUser;

    /**
     * @ORM\Column(type="float")
     */
    private $value;


    public function __construct($song, $user, $rank)
    {
        $this->rankedSong = $song;
        $this->rankedUser = $user;
        $this->value = $rank;
    }

    public function getId()
    {
        return $this->id;
    }

    public function getRankedSong()
    {
        return $this->rankedSong;
    }

    public function getRankedUser()
    {
        return $this->rankedUser;
    }

    public function getValue(){
        return $this->value;
    }

    public function setRankedSong($rankedSong)
    {
        $this->rankedSong = $rankedSong;
    }

    public function setRankedUser($rankedUser)
    {
        $this->rankedUser = $rankedUser;
    }

    public function setValue($newValue){
        $this->value = $newValue;
    }

}

歌曲实体:

namespace App\Entities;

use Doctrine\ORM\Mapping as ORM;
use App\Entities\RankEntity;
use Doctrine\Common\Collections\ArrayCollection;
/**
 * @ORM\Entity
 * @ORM\Table(name="songs")
 */
class SongEntity
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")

     */
    private $id;

    /**
     * @ORM\Column(type="string")
     */
    private $title;

    /**
     * @ORM\Column(type="string")
     */
    private $artist;

    /**
     * @ORM\Column(type="string")
     */
    private $url;



    /**
     * @ORM\ManyToOne(targetEntity="UserEntity")
     */
    private $uploadedUser;

    /**
     * @ORM\OneToMany(targetEntity="RankedEntity", mappedBy="rankedSong")
     * @ORM\JoinColumn(name="id", referencedColumnName="rankedSong")
     */
    private $rank;

    public function __construct($title, $artist, $url, $userID)
    {
        $this->rank = new ArrayCollection();
        $this->title = $title;
        $this->artist = $artist;
        $this->url = $url;
        $this->uploadedUser = $userID;
    }

    public function getId()
    {
        return $this->id;
    }

    public function getTitle()
    {
        return $this->title;
    }

    public function getArtist()
    {
        return $this->artist;
    }

    public function getUrl()
    {
        return $this->url;
    }

    public function getUploadedUser()
    {
        return $this->uploadedUser;
    }

    public function setTitle($title)
    {
        $this->title = $title;
    }

    public function setArtist($artist)
    {
        $this->artist = $artist;
    }

    public function setUrl($url)
    {
        $this->url = $url;

    }
    public function setUploadedUser($user)
    {
        $this->uploadedUser = $user;

    }

    public function getRank(){
        return $this->rank;
    }
    public function setRank($rank){
        $this->rank = $rank;
    }

}

此外,如果我将@ORM \ Column(type =" string")添加到排名中,将成功生成模式,但不会生成外键。我做错了什么?

1 个答案:

答案 0 :(得分:1)

我不是专家,而是在您的用户实体中:

   /**
        * @ORM\OneToMany(targetEntity="**RankedEntity**", mappedBy="rankedSong")
        * @ORM\JoinColumn(name="id", referencedColumnName="rankedSong")
         */
          private $rank;

和你班级的名字 class RankEntity

并没有提及排名 ed 实体

可能是这件事吗?