views:

188

answers:

5

Hey! I just want to know your guys opinion on using join tables within the zend framework.

Of course you can use relations by defining a referenceMap and dependentTables and stuff, or using

setIntegrityCheck(false)

within a db select(). The setIntegrityCheck version seems a little bit dirty to me, but the other version is not very suitable for big querys and joining many tables...

I'm a PHP developer for 5 years now and new to the zend framework and just want get a direction for my first project.

Thanks!!!

A: 

I personally use them all over the place. What I'll usually do is set up a reference map and then have the model defined with a getX() that calls that relation.

class Model_Content extends Zend_Db_Table_Row_Abstract
{
    public function getComments($showInactive = false)
    {
        $select = $this->_table->select();
        if (!$showInactive) {
            $select->where('comment_active = \'y\'');
        }
        return $this->findDependentRowset('Model_DbTable_Comment', null, $select);
    }
}
Kevin Schroeder
A: 

Nice approach... As far as I can see, in ZF there is only the select() thing to get one rowset, which includes data from 2 or more tables, right? For instance, I can have a user and this user has a image and an account. Both are in seperate tables.

When I'm using findDependentRowset, there is no way to get a result like:

username => tom
imagepath => /images/tom.jpg
accounttype => free

within one object, right? Or am I missing something? Thanks for your help!!

rtmilker
A: 

Personally, I use setIntegrityCheck(false) everywhere. Yes, it's kind of dirty but it's KISS and much easier to write complex join queries like that.

Richard Knop
A: 

I'm using setIntegrityCheck(false) as well, because like Richard already said, it's KISS and it's the only option for building big queries. Another nice thing on using select() is, that you can echo it out.

This way you can check your work, which is not that much easy when you're using a referenceMap...

tipclapper
A: 

The findDependentRowset/findParentRow methods are all fair and good unless you are performing queries pulling lots of data. From past experience, using these methods calls another database query even if it has been performed before and I have clocked up a lot of data traffic between the web and database servers. In that particular case, the application then needed to be converted to use the join method.

However, the findDependentRowset and findParentRow methods have their advantage to allow you to then recall the same methods on the new Zend_Db_Table_Row object from your joined table.

rtmilker: The findDependentRowset should return an array of Zend_Db_Table_Rows so in that case:

foreach($myTableAdapter->findDependentRowset('New_Table_Class', 'rule/[null]', $select) as $dependentRowObject){
    Zend_Debug::dump($dependentRowObject->toArray());
}

The findParentRow method would obviously not require the foreach statement; same kind of thing with the fetchRow()/fetchAll() methods.

lintal