Haresh Chaudhary
Haresh Chaudhary

Reputation: 4400

Unable to perform the JOIN between branched folders in Zend

I am trying to fire a query which should give me result from multiple table.... I am doing JOIN in zend framework 1.10.0 ... but the problem is that i am having tables which are connected as a branch.
for example

Table 1 (T1 PK)  
    Table 2 (T2 PK, T1 FK)  
    Table 3 (T3 PK, T1 FK)  
    Table 4 (T4 PK, T2 FK)  
    Table 5 (T5 PK, T1 FK)  

Now, i am able to join Table1, with Table2, Table3 & Table5, but the problem is what should i do with Table4, bcoz i want data from that table also... How can I make a query which can do Branch JOINS ... Working on this from 2 days ... Plz help me frnds ... Thanks In Advance

Upvotes: 1

Views: 75

Answers (1)

Jerec TheSith
Jerec TheSith

Reputation: 1942

I haven't tested it but it should be ok.

When joining tables you must must specify the conditional expression of the join. So you just have to reference the right table when joining T4

$dbTable = new Aplication_Model_DbTable_T1();
$select = $dbTable->select()
                  ->setIntegrityCheck(false)
                  ->from(array("t1" => "table1"), array(t1 columns to fetch...))
                  ->join(array("t2" => "table2"), "t2.t1 = t1.id",array(t2 cols to fetch))
                  ->join(array("t3" => "table3"), "t3.t1 = t1.id",array(t3 cols to fetch))
                  ->join(array("t4" => "table4"), "t4.t2 = t2.id",array(t4 cols to fetch))
                  ->join(array("t4" => "table4"), "t5.t1 = t1.id",array(t4 cols to fetch))
                  ->where(...);

Upvotes: 1

Related Questions