2010-10-30 140 views
1
class Profile { 
    /** @OneToMany(targetEntity="Link", mappedBy="owner") */ 
    private $links; 
} 

class Link { 
    /** 
    * @ManyToOne(targetEntity="Profile", inversedBy="links") 
    * @JoinColumn(name="owner_id", referencedColumnName="id") 
    */  
    public $owner; 
    /** 
    * @ManyToOne(targetEntity="Profile") 
    * @JoinColumn(name="subject_id", referencedColumnName="id") 
    */  
    public $subject;  
} 

$em->findBy(array("owner"=>$owner,"subject"=>$subject)); 

給 無法識別的領域:業主findBy關係領域

當然還有一種解決方法,但它看起來醜陋

$em 
->createQuery('SELECT l FROM \Dating\Models\Link l WHERE l.owner = ?1 AND l.subject = ?2') 
->setParameter(1,$owner) 
->setParameter(2,$subject) 
->getResult(); 

是有使用findBy沒有寫我自己的方法的任何機會呢?

+0

你有沒有想過這個?如果不是,我可能會爲您提供解決方案。 – Squazic 2012-08-01 20:23:35

回答

1

所有內容在您的代碼中都是正確的。 Doctrine2目前處於測試階段,這是beta4中的一個錯誤。嘗試從GIT下載最新版本,它應該工作!

0

owner不是一個字段,owner_id是。嘗試使用它。

+0

結果於:無法識別的字段:owner_id – BoomyJee 2010-10-30 15:10:08