0
我從學說1.2遷移到學說2.1時遇到用應該是什麼簡單的連接問題麻煩與Doctrine2連接表
這是我的第一個表:
/**
* Model_WBS
*
* @Table(name="WBS")
* @Entity
*/
class Model_Wbs
/**
* @var integer $id
*
* @Column(name="id", type="integer", length=8)
* @Id
* @GeneratedValue(strategy="SEQUENCE")
* @SequenceGenerator(sequenceName="wbs_seq_seq", allocationSize=1, initialValue=1)
*/
public $id;
.
.
.
/**
* @var \Doctrine\Common\Collections\ArrayCollection
*
* @OneToMany(targetEntity="Model_WbsFund", mappedBy="id")
* @JoinColumn(name="id", referencedColumnName="wbs_id")
*/
public $wbsfunds;
這是我第二次表
/**
* Model_WbsFund
*
* @Table(name="WBS_FUNDS")
* @Entity
*/
class Model_WbsFund
/**
* @var integer $id
*
* @Column(name="id", type="integer", length=8)
* @Id
* @GeneratedValue(strategy="SEQUENCE")
* @SequenceGenerator(sequenceName="wbs_funds_seq_seq", allocationSize=1, initialValue=1)
*/
public $id;
/**
* @var integer $wbs_id
*
* @Column(name="wbs_id", type="integer", length=8)
*/
public $wbs_id;
.
.
.
/**
* @var \Doctrine\Common\Collections\ArrayCollection
*
* @ManyToOne(targetEntity="Model_Wbs", inversedBy="wbs_id")
* @JoinColumn(name="wbs_id", referencedColumnName="id")
*/
public $WBS;
這裏是我的簡單測試
$testEntity = Model_Wbs::find(7185);
foreach($testEntity->getwbsfunds() as $wbsfundobj){
print("<br/>");
print($wbsfundobj->FUND->getFundCode()." -- ".$wbsfundobj->WBS->getWbs());
}
所以我期望看到與我第一次搜索的wbs相關聯的wbsfunds表中的基金代碼和wbs。 (我把 - > WBS-> getWbs()看看我是否真正獲得了與wbs id 7185相關的資金)。
取而代之,我得到所有wbs_funds記錄。我打印出來生成的查詢語句的學說,它是不正確
SELECT t0.id AS ID1, t0.wbs_id AS WBS_ID2, t0.fund_id AS FUND_ID3, t0.wbs_id AS WBS_ID4, t0.fund_id AS FUND_ID5 FROM WBS_FUNDS t0
有趣的是,> wbsfundobj->賠償基金撥款─之間的聯繫geFundCode()的偉大工程,一樣的wbsfundobj-> WBS-> getWBS( ),但從WBS到WBS_FUNDS的鏈接看起來不對。
喜歡受保護的屬性,而不是公共的。 http://stackoverflow.com/questions/4090609/how-can-public-fields-break-lazy-loading-in-doctrine-2 – Florian 2012-02-02 23:29:12