2014-06-05 73 views
6

基本問題:學說2映射引用唯一鍵

是否有可能使用到的關聯映射學說引用不是主要,但只有一個唯一的密鑰?

擴展版本:

我有一個實體(Participation),其可參考其他2個實體(DropoutCauseDischargeType)。根據這個組合,基於數據庫中的另一個(4th)表(DropoutScenario)暗示其他一些屬性。因爲兩個引用的實體中的任何一個都可能爲空,所以我無法將它們聲明爲主鍵,但只有第四個表中的唯一鍵。

問題是,當我嘗試使用Doctrine映射此我只得到一個錯誤:

上 應用\實體\培訓\主鍵ID

缺少值DropoutScenario

上午我做錯了什麼,或者這是根本不可能與教條? 如果沒有,有沒有更好的解決方案,我可以做到這一點?

我一直在尋找一個相當長的時間,挖學說文檔,但我根本無法找到這樣的東西...

我映射的剝離代碼示例如下。

參與:

<?php 

namespace Application\Entity\Trainings; 

use Doctrine\ORM\Mapping as ORM; 

/** 
* @ORM\MappedSuperclass 
*/ 
abstract class Participation { 

    /** 
    * @ORM\Id 
    * @ORM\Column(type="integer") 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    protected $id; 

    /** 
    * @ORM\ManyToOne(targetEntity="Application\Entity\DropoutCause") 
    * @ORM\JoinColumn(name="dropout_cause_id", referencedColumnName="id")) 
    */ 
    protected $dropoutCause; 

    /** 
    * @ORM\ManyToOne(targetEntity="Application\Entity\DischargeType") 
    * @ORM\JoinColumn(name="discharge_id", referencedColumnName="id")) 
    */ 
    protected $dischargeType; 

    /** 
    * @ORM\ManyToOne(targetEntity="DropoutScenario") 
    * @ORM\JoinColumns({ 
    * @ORM\JoinColumn(name="discharge_id", referencedColumnName="discharge_id"), 
    * @ORM\JoinColumn(name="dropout_cause_id", referencedColumnName="dropout_cause_id") 
    * }) 
    */ 
    private $scenario; 

DropoutScenario:

<?php 

namespace Application\Entity\Trainings; 

use Doctrine\ORM\Mapping as ORM; 

/** 
* @ORM\Entity 
* @ORM\Table(name="training_dropout_scenarios") 
*/ 
class DropoutScenario { 

    /** 
    * @var int 
    * @ORM\Id 
    * @ORM\Column(type="integer") 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    protected $id; 

    /** 
    * @ORM\ManyToOne(targetEntity="Application\Entity\DropoutCause") 
    * @ORM\JoinColumn(name="dropout_cause_id", referencedColumnName="id")) 
    */ 
    protected $dropoutCause; 

    /** 
    * @ORM\ManyToOne(targetEntity="Application\Entity\DischargeType") 
    * @ORM\JoinColumn(name="discharge_id", referencedColumnName="id")) 
    */ 
    protected $dischargeType; 

    /** @ORM\Column(type="integer", name="dropout_cause_id") */ 
    protected $dropoutCauseId; 

    /** @ORM\Column(type="integer", name="discharge_id") */ 
    protected $dischargeTypeId; 

回答

6

因爲我沒有得到任何答案了我所做的另一項研究今天,我找到了答案,以我自己的問題通過學說郵件列表論壇。 似乎我剛剛搜索了錯誤的關鍵字...

原則2不幸地不支持它。太遺憾了! :(

從學說文檔: http://doctrine-orm.readthedocs.org/en/latest/reference/limitations-and-known-issues.html#join-columns-with-non-primary-keys

這是不可能使用加入指向非主鍵列 主義會認爲這些都是主鍵和創建延遲加載 。原因 出於性能方面的原因不能在運行時驗證此 設置的正確性,但只能通過驗證架構命令驗證。

類似的問題: Is it possible to reference a column other than 'id' for a JoinColumn?