Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-19-2008, 04:28 PM
Junior Member
 
Join Date: Jun 2008
Posts: 2
Default Zend_Db_Table join

Hi everyone, I am fairly new to the zend framework as well as php.

I am creating a website that for simplicity could be described as a blog which has Sections which contain Categories which contain Entries.

lets say I have a URL in the following form:
http://localhost/Some_Section/A_Category/An_Entry

I have taken care of the routing and get back 3 parameters
$section
$category
$entry

My database contains 3 tables: 'Section', 'Category' and 'Entry' which i have created models for by extending Zend_Db_Table. The Entry table contains a foreign key to the Category id. The Category table contains a foreign key to the Section id.

in order to get the proper data I need to do a join on the 3 tables but I do not want to be forced to specify all the column names after the join... especial since all of the columns are uniquely named. I have found that this can be done with the joinUsing() function but I cant use it on 3 tables.

this is what i have used to join 2 tables in the entries model. could anyone help me figure out how to get the same type of thing done with 3?

PHP Code:
 // this function fetches entries in a category by date or by votes or both
 
public function fetchEntries($category$byDate false$byVotes true$count 10)
    {
        
$select $this->select(); 
        
$select->setIntegrityCheck(false)
               ->
from('entries')
               ->
joinUsing('categories','category_id')   
               ->
limit($count);
        
        
$order = array();
        
        if(
$byDate)
        
$order[] = 'entry_date DESC';
        
        if(
$byVotes)
        
$order[] = 'entry_votes DESC';
        
        
$select->order($order);                   
        
$select->where('categories.category_safe_title = ?'$category);
               
        return 
$this->fetchAll($select);
    } 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
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



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