ZF-1674: Allow row relationship methods to specify WHERE, ORDER and LIMIT clauses

Issue Type: Improvement Created: 2007-07-02T20:43:29.000+0000 Last Updated: 2008-01-18T21:34:12.000+0000 Status: Resolved Fix version(s): Reporter: Simon Mundy (peptolab) Assignee: Simon Mundy (peptolab) Tags: - Zend_Db_Table

Related issues: - ZF-1182



Rowsets currently allow for the following:-

<pre class="highlight">
findDependentRowset($dependentTable, $ruleKey = null)
findParentRow($parentTable, $ruleKey = null)
findManyToManyRowset($matchTable, $intersectionTable, $callerRefRule = null, $matchRefRule = null)

It would be great to extend these method signatures to include custom WHERE, ORDER and LIMIT clauses in much the same way as the parent table fetchAll method so the results can be fine-tuned:-

<pre class="highlight">
findDependentRowset($dependentTable, $ruleKey = null, Array $where = array(), $order = null, $limit = null, $offset = null)
findParentRow($parentTable, $ruleKey = null, Array $where = array(), $order = null, $limit = null, $offset = null)
findManyToManyRowset($matchTable, $intersectionTable, $callerRefRule = null, $matchRefRule = null, Array $matchParams = array())

This would then be applied to each applicable method as follows:

<pre class="highlight">
public function findDependentRowset($dependentTable, $ruleKey = null, Array $where = array(), $order = null, $limit = null, $offset = null)
    return $dependentTable->fetchAll($where, $order, $limit, $offset);

public function findParentRow($parentTable, $ruleKey = null, Array $where = array(), $order = null)
    return $parentTable->fetchRow($where, $order);

The many-to-many method is obviously a little more complex as multiple tables are involved, but perhaps an associative array called $matchParams could handle this with a per-table array of where, order, limit and offset:-

<pre class="highlight">
$matchParams = array(
    'table1' => array(
        'where' => array('foo in (1,2,3)', 'bar in (3,4,5)'),
        'order' => 'name ASC',
        'limit' => 5
    'table2' => array(
        'where' => array('foo in (1,2,3)', 'bar in (3,4,5)'),
        'order' => 'name ASC',
        'limit' => 5


Posted by Alan Gabriel Bem (alan.bem) on 2007-07-02T21:18:19.000+0000

I have reported that long time ago. The answer was simple - no.

Posted by Bill Karwin (bkarwin) on 2007-07-20T21:03:44.000+0000

I think we can consider this use case now.

I'd suggest we use the proposal process to design a comprehensive solution to this. I would suggest we use Zend_Db_Select objects as optional arguments to Zend_Db_Table and Zend_Db_Table_Row methods. That way we can specify many SQL clauses without having to add a long list of optional arguments.

Posted by Craig Slusher (sleek) on 2007-09-12T18:39:21.000+0000

I would argue that $order, $count, and $offset are the only additional parameters that would be beneficial to add to the relationship methods.

If you think about it, the final result is to call either fetchAll() or fetchRow(). Since the where clause is being determined within the relationship logic, there's no reason to allow the user to have any say in it. However, if you allow the user to specify $order, $count, and $offset, then it becomes extremely useful. $order would be defined in terms of the related table columns, and not from the table that your current row came from.

I find myself not using the relationship methods and ducking directly into my own queries just to get the ability to order and limit. Seems so unnecessary to me.

The change is very simple and I think it would be hugely beneficial.

Posted by Bill Karwin (bkarwin) on 2007-09-12T18:55:18.000+0000

You might like to look at the following proposal:…

Posted by Darby Felton (darby) on 2007-10-31T11:56:17.000+0000

Assigning to [~peptolab] to be resolved with the approved Zend_Db_Table enhancements proposal.

Posted by Simon Mundy (peptolab) on 2008-01-18T21:34:12.000+0000

Resolved in r7508

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.