[DDC-1705] BasicEntityPersister throws error undefined index Created: 15/Mar/12  Updated: 01/Apr/12  Resolved: 01/Apr/12

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: 2.2
Fix Version/s: 2.2.2
Security Level: All

Type: Bug Priority: Major
Reporter: victor Velkov Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 1
Labels: None


 Description   

In the BasicEntityPersister in the _getInsertSQL function when you are foreaching the columns you make a check

if (isset($this->_columnTypes[$column]) &&
                        isset($this->_class->fieldMappings[$this->_class->fieldNames[$column]]['requireSQLConversion'])) {
                        $type = Type::getType($this->_columnTypes[$column]);
                        $placeholder = $type->convertToDatabaseValueSQL('?', $this->_platform);
                    }

the problem is in

  isset($this->_class->fieldMappings[$this->_class->fieldNames[$column]]['requireSQLConversion'])

because you are not checking if it is set

$this->_class->fieldNames[$column]

i got that problem when was saving ManyToOne association



 Comments   
Comment by Sascha Nordquist [ 19/Mar/12 ]

I got the same error and used error handling to throw an exception of this notice:

===================
PHP Fatal error: Uncaught exception 'ErrorException' with message 'Undefined index: currentPrice_id' in /usr/share/php/Doctrine/ORM/Persisters/BasicEntityPersister.php:1146
Stack trace:
#0 /usr/share/php/Doctrine/ORM/Persisters/BasicEntityPersister.php(1146): exception_error_handler(8, 'Undefined index...', '/usr/share/php/...', 1146, Array)
#1 /usr/share/php/Doctrine/ORM/Persisters/BasicEntityPersister.php(225): Doctrine\ORM\Persisters\BasicEntityPersister->_getInsertSQL()
#2 /usr/share/php/Doctrine/ORM/UnitOfWork.php(896): Doctrine\ORM\Persisters\BasicEntityPersister->executeInserts()
#3 /usr/share/php/Doctrine/ORM/UnitOfWork.php(304): Doctrine\ORM\UnitOfWork->executeInserts(Object(Doctrine\ORM\Mapping\ClassMetadata))
#4 /usr/share/php/Doctrine/ORM/EntityManager.php(355): Doctrine\ORM\UnitOfWork->commit(NULL)
#5 /var/www/app/module/Application/src/Application/Entity/Model.php(29): Doctrine\ORM\EntityManager->flush()
#6 /var/www/app/module/Application/src/Application/Entity/ in /usr/share/php/Doctrine/ORM/Persisters/BasicEntityPersister.php on line 1146

===================

My mappings look like this:

/**

  • @ORM\OneToMany(targetEntity="Price", mappedBy="product", cascade= {"all"})
    * @ORM\OrderBy({"date" = "DESC"})
    */
    protected $prices;

    /**
    * @ORM\ManyToOne(targetEntity="Price", inversedBy="currentProducts",cascade={"all"}

    )
    */
    protected $currentPrice;

Comment by Benjamin Eberlei [ 01/Apr/12 ]

Fixed

Generated at Sat Apr 19 10:17:20 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.