0
我有一個使用複合主鍵引用另一個實體的實體。複合主鍵上的外鍵不起作用
我只是在做一個ManyToOne關係。每家公司可以有很多交易。每家公司都是某些證券交易所的一部分,其唯一標識符既是其上市的證券交易所,也是其股票代碼。
,我得到的,當我嘗試更新架構的錯誤是:
Column name ``id`` referenced for relation from Application\Entity\Trade towards Application\Entity\Company does not exist.
我認爲這是試圖默認id
的公司。有沒有辦法在一個表上爲主鍵指定多個外鍵?
<?php
namespace Application\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity
* @ORM\Table(name="trade")
*/
class Trade
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(name="id",type="integer")
*/
protected $id;
/**
* @ORM\Column(type="integer")
*/
protected $price;
/**
* @ORM\Column(type="integer")
*/
protected $size;
/**
* @ORM\Column(type="datetime")
*/
protected $dateTime;
/**
* @ORM\ManyToOne(targetEntity="Application\Entity\Company", inversedBy="trade")
*/
protected $company;
/**
* @return mixed
*/
public function getPrice()
{
return $this->price;
}
/**
* @param mixed $price
*/
public function setPrice($price)
{
$this->price = $price;
}
/**
* @return mixed
*/
public function getSize()
{
return $this->size;
}
/**
* @param mixed $size
*/
public function setSize($size)
{
$this->size = $size;
}
/**
* @return mixed
*/
public function getDateTime()
{
return $this->dateTime;
}
/**
* @param mixed $dateTime
*/
public function setDateTime($dateTime)
{
$this->dateTime = $dateTime;
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @param mixed $id
*/
public function setId($id)
{
$this->id = $id;
}
/**
* @return mixed
*/
public function getCompany()
{
return $this->company;
}
/**
* @param mixed $company
*/
public function setCompany($company)
{
$this->company = $company;
}
}
這裏的實體公司是否有幫助
<?php
namespace Application\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity
* @ORM\Table(name="company")
*/
class Company
{
/**
* @ORM\Id
* @ORM\Column(length=5)
*/
protected $symbol;
/**
* @ORM\Id @ORM\ManyToOne(targetEntity="\Application\Entity\Exchange", inversedBy="company")
* @ORM\JoinColumn(name="exchangeKey", referencedColumnName="exchangeKey")
*/
protected $exchange;
/**
* @return mixed
*/
public function getSymbol()
{
return $this->symbol;
}
/**
* @param mixed $symbol
*/
public function setSymbol($symbol)
{
$this->symbol = $symbol;
}
/**
* @return mixed
*/
public function getExchange()
{
return $this->exchange;
}
/**
* @param mixed $exchange
*/
public function setExchange($exchange)
{
$this->exchange = $exchange;
}
}