TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-29-2010, 10:49 AM   #1 (permalink)
The Acquainted
 
JaoudeStudios's Avatar
 
Join Date: Jul 2009
Location: Surrey
Posts: 105
Thanks: 1
JaoudeStudios is on a distinguished road
Default 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.com | JaoudeStudios.com Forum | JaoudeStudios.com Blog
OpenSource is the road ahead...!
JaoudeStudios is offline  
Reply With Quote
Old 01-31-2010, 09:52 AM   #2 (permalink)
The Acquainted
 
JaoudeStudios's Avatar
 
Join Date: Jul 2009
Location: Surrey
Posts: 105
Thanks: 1
JaoudeStudios is on a distinguished road
Default

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.
__________________
JaoudeStudios.com | JaoudeStudios.com Forum | JaoudeStudios.com Blog
OpenSource is the road ahead...!
JaoudeStudios is offline  
Reply With Quote
Old 02-24-2010, 01:38 AM   #3 (permalink)
The Contributor
 
Join Date: Feb 2007
Posts: 64
Thanks: 9
Killswitch is on a distinguished road
Default

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).
Killswitch is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Mail - Help sending multiple attachments xperience Absolute Beginners 5 09-06-2010 08:27 AM
Passing multiple arguments to a function via one variable. delayedinsanity Advanced PHP Programming 10 05-07-2008 05:04 AM
Storing multiple file paths inside a database Orc General 10 02-17-2008 04:29 AM
Multiple Servers? Sam Granger Advanced PHP Programming 5 02-08-2008 03:14 PM


All times are GMT. The time now is 12:23 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design