I am migrating from Doctrine 1.2 to Doctrine 2.1 and am having problems with what should be a simple join
This is my first table:
/**
* 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;
And this is my second table
/**
* 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;
And here is my simple test
$testEntity = Model_Wbs::find(7185);
foreach($testEntity->getwbsfunds() as $wbsfundobj){
print("<br/>");
print($wbsfundobj->FUND->getFundCode()." -- ".$wbsfundobj->WBS->getWbs());
}
So I would expect to see the fund code and the wbs from the wbsfunds table that are associated with the wbs I first searched. (I put in the ->WBS->getWbs() to see if I was actually getting just the funds related to wbs id 7185).
Instead, I get all wbs_funds records. I printed out the query statement doctrine generated and it's not correct
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
The interesting thing is that the link between wbsfundobj->FUND->geFundCode() works great, as does the wbsfundobj->WBS->getWBS(), but the link from WBS to WBS_FUNDS seems wrong.