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