TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   ZF: Models multiple joins (http://www.talkphp.com/advanced-php-programming/5239-zf-models-multiple-joins.html)

JaoudeStudios 01-29-2010 10:49 AM

ZF: Models multiple joins
 
Hi,

I will cut down my issue for simplicity.

I have 4 tables:
Jobs
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | YES | | NULL | |
+-------------+--------------+------+-----+---------+----------------+

Test Runs
+------------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| job_id | int(11) | YES | | NULL | |
| browser_id | int(11) | YES | | NULL | |
+------------+----------+------+-----+---------+----------------+

Browsers
+---------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | YES | | NULL | |
| version_major | int(11) | YES | | NULL | |
| version_minor | int(11) | YES | | NULL | |
+---------------+--------------+------+-----+---------+----------------+

Pages
+-------------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| test_run_id | int(11) | YES | | NULL | |
| created_at | datetime | YES | | NULL | |
| updated_at | datetime | YES | | NULL | |
| total | int(11) | YES | | NULL | |
| dynamic | tinyint(1) | YES | | NULL | |
+-------------------+--------------+------+-----+---------+----------------+

I would like to join all the tables together with Jobs at the top of the tree. I can easily do it in mysql, but I would like to use the ZF models rules. I think I have the rules setup correctly, just not sure how to get the info.

Here it is when I wrote it manual:
[code=text]public function browserList($job_id)
* * {
* * * * # query
* * * * $select = $this->select()
* * * * * * * * * * * * ->setIntegrityCheck(false)
* * * * * * * * * * * * ->from($this->_name)
* * * * * * * * * * * * ->joinLeft('browsers', 'test_runs.browser_id = browsers.id', array('*'))
* * * * * * * * * * * * ->joinLeft('pages', 'test_runs.id = pages.test_run_id', array('total', 'pages.id as page_id'))
* * * * * * * * * * * * ->where('test_runs.job_id = ?', (int) $job_id);
* * * * $results = $this->fetchAll($select);* * * *
* * * * return $results;
* * }[/code]

This is what I have attempted to do...
[code=text]# get job id
* * * * $job_id = (int) $request->getParam('job_id');* ** *
* * * *
* * * * # get test run info inc. browser, page
* * * * $jobs = new Default_Model_DbTables_Jobs(array('db'=>'shard1')) ;
* * * * $jobDetails = $jobs->find($job_id)->current();
* * * * $testRuns = $jobDetails->findDependentRowset('Default_Model_DbTables_TestR uns');
* * * *
* * * * $browserList = $testRuns->findDependentRowset('Default_Model_DbTables_Brows ers');[/code]
But I get an error 'fatal error: Call to undefined method Zend_Db_Table_Rowset::findDependentRowset()', and yet I still need to join on another table shortly.

Any help much appreciated, been at it for a couple of days and thinking of giving up. :banghead:

JaoudeStudios 01-31-2010 09:52 AM

No one seems to have an answer in any of the forums I posted in...hmmmm is this a limitation of ZF? I have decided to use Doctrine for the database abstraction layer. Integrating it into ZF was not too bad (ish), but the power of Active records is great, I definitely recommend using Zend Framework with Doctrine. From what I understand in the near future this will be seamlessly integrated together. Hope that helps others.

Killswitch 02-24-2010 01:38 AM

Does Zend not have an ORM feature? I haven't used Zend at all, but love Kohana for the ORM (I just glanced at Doctrine, seems to do quite the same thing).


All times are GMT. The time now is 01:57 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0