当我尝试运行php artisan doctrine:schema:create
从实体生成架构时,发生错误。
[Doctrine\ORM\Mapping\MappingException] 在"App\Entities\SongEntity#rank"中找不到目标实体 App\Entities\RankedEntity
。我正在尝试在这里进行一对多映射。其中每个歌曲实体可以映射到许多排名实体。这是两个实体。排名实体:
namespace AppEntities;
use DoctrineORMMapping as ORM;
/**
* @ORMEntity
* @ORMTable(name="ranks")
*/
class RankEntity
{
/**
* @ORMId
* @ORMManyToOne(targetEntity="SongEntity", inversedBy="rank")
* @ORMJoinColumn(name="rankedSong", referencedColumnName="id")
*/
private $rankedSong;
/**
* @ORMId
* @ORMManyToOne(targetEntity="UserEntity")
*/
private $rankedUser;
/**
* @ORMColumn(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 AppEntities;
use DoctrineORMMapping as ORM;
use AppEntitiesRankEntity;
use DoctrineCommonCollectionsArrayCollection;
/**
* @ORMEntity
* @ORMTable(name="songs")
*/
class SongEntity
{
/**
* @ORMId
* @ORMGeneratedValue
* @ORMColumn(type="integer")
*/
private $id;
/**
* @ORMColumn(type="string")
*/
private $title;
/**
* @ORMColumn(type="string")
*/
private $artist;
/**
* @ORMColumn(type="string")
*/
private $url;
/**
* @ORMManyToOne(targetEntity="UserEntity")
*/
private $uploadedUser;
/**
* @ORMOneToMany(targetEntity="RankedEntity", mappedBy="rankedSong")
* @ORMJoinColumn(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"(添加到rank,架构将成功生成,但不会生成外键。我做错了什么?
我不是专家,但在您的用户实体中:
/**
* @ORMOneToMany(targetEntity="**RankedEntity**", mappedBy="rankedSong")
* @ORMJoinColumn(name="id", referencedColumnName="rankedSong")
*/
private $rank;
和您的班级名称 类排名实体
并且没有引用排名ed实体
也许围绕这个?