Issues

ZF2-66: Error in the class Zend\Db\Table\AbstractTable in the method getReference().

Issue Type: Bug Created: 2011-09-08T09:31:35.000+0000 Last Updated: 2011-11-22T09:02:42.000+0000 Status: Resolved Fix version(s): Reporter: Nilov Andrey (nilov) Assignee: Fabio B. Silva (fabio.bat.silva) Tags: - Zend\Db

  • AbstractTable
  • Zend_Db

Related issues: Attachments:

Description

Error in the class Zend\Db\Table\AbstractTable in the method getReference(). On line 468 there is no processing of the table class name (do not add a slash at the beginning), which is why there is a difference between "get_class($this)" and "$tableClassname" and resulting in the table class name is not in the "$_referenceMap" and throws exception: "Reference rule \" $ ruleKey \ "does not reference table $ tableClassname".

Solution: Make the processing of the variable $tableClassname at the beginning of the method.

<pre class="highlight">
    /**
     * @param string $tableClassname
     * @param string $ruleKey OPTIONAL
     * @return array
     * @throws \Zend\Db\Table\Exception
     */
    public function getReference($tableClassname, $ruleKey = null)
    {
        $tableClassname = '\\' . ltrim($tableClassname, '\\');
        $thisClass = get_class($this);
        if ($thisClass === 'Zend\Db\Table\Table') {
            $thisClass = $this->_definitionConfigName;
        }
        $refMap = $this->_getReferenceMapNormalized();
        if ($ruleKey !== null) {
            if (!isset($refMap[$ruleKey])) {
                throw new Exception("No reference rule \"$ruleKey\" from table $thisClass to table $tableClassname");
            }
            if ($refMap[$ruleKey][self::REF_TABLE_CLASS] != $tableClassname) {
                throw new Exception("Reference rule \"$ruleKey\" does not reference table $tableClassname");
            }
            return $refMap[$ruleKey];
        }
        foreach ($refMap as $reference) {
            if ($reference[self::REF_TABLE_CLASS] == $tableClassname) {
                return $reference;
            }
        }
        throw new Exception("No reference from table $thisClass to table $tableClassname");
    }

Comments

Posted by Nilov Andrey (nilov) on 2011-09-08T13:18:34.000+0000

Solution:

<pre class="highlight">
    /**
     * @param string $tableClassname
     * @param string $ruleKey OPTIONAL
     * @return array
     * @throws \Zend\Db\Table\Exception
     */
    public function getReference($tableClassname, $ruleKey = null)
    {
        $tableClassname = '\\' . ltrim($tableClassname, '\\');
        $thisClass = get_class($this);
        if ($thisClass === 'Zend\Db\Table\Table') {
            $thisClass = $this->_definitionConfigName;
        }
        $refMap = $this->_getReferenceMapNormalized();
        if ($ruleKey !== null) {
            if (!isset($refMap[$ruleKey])) {
                throw new Exception("No reference rule \"$ruleKey\" from table $thisClass to table $tableClassname");
            }
            if ($refMap[$ruleKey][self::REF_TABLE_CLASS] != $tableClassname) {
                throw new Exception("Reference rule \"$ruleKey\" does not reference table $tableClassname");
            }
            return $refMap[$ruleKey];
        }
        foreach ($refMap as $reference) {
            if ($reference[self::REF_TABLE_CLASS] == $tableClassname) {
                return $reference;
            }
        }
        throw new Exception("No reference from table $thisClass to table $tableClassname");
    }

Posted by Benoît Durand (intiilapa) on 2011-09-11T06:11:01.000+0000

Add code tags.

Posted by Fabio B. Silva (fabio.bat.silva) on 2011-11-21T19:59:17.000+0000

Fixed : https://github.com/zendframework/zf2/pull/619

Posted by Ramon Henrique Ornelas (ramon) on 2011-11-22T09:02:42.000+0000

I would not worry with fix of issues Zend\Db because this go be refactoring in version 2 still ;). http://framework.zend.com/wiki/display/…. https://github.com/ralphschindler/zf2-db.

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