Issues

ZF-439: Zend_Db_Table ORM implementation

Issue Type: Improvement Created: 2006-10-11T16:20:52.000+0000 Last Updated: 2007-07-05T14:43:20.000+0000 Status: Resolved Fix version(s): - 0.9.0 (17/Mar/07)

Reporter: Eugene Panaitov (eugenep) Assignee: Bill Karwin (bkarwin) Tags: - Zend_Db_Table

Related issues: Attachments:

Description

per http://framework.zend.com/wiki/display/…

<pre class="highlight">
<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * <a href="http://framework.zend.com/license/new-bsd">http://framework.zend.com/license/new-bsd</a>
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Db
 * @subpackage Table
 * @copyright  Copyright (c) 2006 Zend Technologies USA Inc. (<a href="http://www.zend.com">http://www.zend.com</a>)
 * @license    <a href="http://framework.zend.com/license/new-bsd">http://framework.zend.com/license/new-bsd</a>     New BSD License
 */ 

Zend::loadClass("Zend_Db_Table");

class Zend_Db_Table_Orm extends Zend_Db_Table {
    
    //per <a href="http://framework.zend.com/wiki/display/ZFMLGEN/mail/1625">http://framework.zend.com/wiki/display/…</a>
    protected $_rowClassName = 'Zend_Db_Table_Row';
    protected $_rowsetClassName = 'Zend_Db_Table_Rowset';
    protected $_dirs = null; // to support db_row classes in different directories
    
    /**
     * Fetches all rows.
     *
     * Honors the Zend_Db_Adapter fetch mode.
     *
     * @param string|array $where An SQL WHERE clause.
     * @param string|array $order An SQL ORDER clause.
     * @param int $count An SQL LIMIT count.
     * @param int $offset An SQL LIMIT offset.
     * @return mixed The row results per the Zend_Db_Adapter fetch mode.
     */
    public function fetchAll($where = null, $order = null, $count = null,
        $offset = null)
    {
        
        $className = $this->_rowsetClassName;
        Zend::loadClass($className, $this->_dirs);
        
        return new $className(array(
            'db'    => $this->_db,
            'table' => $this,
            'data'  => $this->_fetch('All', $where, $order, $count, $offset),
        ));
    }
    
    /**
     * Fetches one row.
     *
     * Honors the Zend_Db_Adapter fetch mode.
     *
     * @param string|array $where An SQL WHERE clause.
     * @param string|array $order An SQL ORDER clause.
     * @return mixed The row results per the Zend_Db_Adapter fetch mode.
     */
    public function fetchRow($where = null, $order = null)
    {
        $className = $this->_rowClassName;
        Zend::loadClass($className, $this->_dirs);
        
        return new $className(array(
            'db'    => $this->_db,
            'table' => $this,
            'data'  => $this->_fetch('Row', $where, $order, 1),
        ));
    }
    
    /**
     * Fetches a new blank row (not from the database).
     * 
     * @return _rowClassName class
     */
    public function fetchNew()
    {
        $keys = array_keys($this->_cols);
        $vals = array_fill(0, count($keys), null);
        
        $className = $this->_rowClassName;
        Zend::loadClass($className, $this->_dirs);
        
        return new $className(array(
            'db'    => $this->_db,
            'table' => $this,
            'data'  => array_combine($keys, $vals),

        ));
    }
    
}

?>

Comments

Posted by Gavin (gavin) on 2006-10-11T17:29:02.000+0000

Super simple, super short, and very easy to use. However, we do not add classes or components to the ZF without a proposal. Please make a new proposal by clicking on the "Submit a new proposal" link in the blue box at the top of this page: http://framework.zend.com/wiki/display/ZFPROP/Home

I know many of us do not like filling out forms, but do not worry about the English wording. Just copy things from this issue, and make a few notes. The proposal is like code. Write a little code and then worry about adding more details later. Time permitting, I will help some also :)

If you write "Please help edit and improve this proposal" at the top of the new proposal, I am sure other community members will help with some of the details.

Posted by Gavin (gavin) on 2006-10-26T14:06:06.000+0000

This issue should be closed when the review process completes for the proposal below:

http://framework.zend.com/wiki/x/bx0

Posted by Bill Karwin (bkarwin) on 2006-11-13T15:22:38.000+0000

Changing fix version to 0.8.0.

Posted by Bill Karwin (bkarwin) on 2007-01-05T17:06:26.000+0000

Recategorize as Zend_Db_Table component.

Posted by Bill Karwin (bkarwin) on 2007-03-15T20:11:09.000+0000

The requirements described in this issue duplicate those of ZF-38, even though the solution is slightly different.

Have you found an issue?

See the Overview section for more details.

Copyright

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

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

Contacts