我在Doctrine中收到以下错误,我的猜测是两个相关实体的映射存在问题:
at ErrorHandler->handle('8', 'Undefined index: fooId', 'vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php', '685', array('entity' => object(FooCategory), 'result' => array(),
'uow' => object(UnitOfWork), 'versioned' => null, 'field' => 'foo', 'change' => array(null, object(FooTranslation)), 'newVal' => object(FooTranslation), 'assoc' => array('fieldName' => 'foo',
'targetEntity' => 'XXX\SomeBundle\Entity\FoonTranslation', 'joinColumns' => array(array('name' => 'foo_id', 'unique' => true, 'nullable' => true, 'onDelete' => null,
'columnDefinition' => null, 'referencedColumnName' => 'foo_id')), 'mappedBy' => null, 'inversedBy' => null, 'cascade' => array(), 'orphanRemoval' => false, 'fetch' => '2', 'type' => '1', 'isOwningSide' => true,
'sourceEntity' => 'XXX\SomeBundle\Entity\FooCategory', 'isCascadeRemove' => false, 'isCascadePersist' => false, 'isCascadeRefresh' => false, 'isCascadeMerge' => false, 'isCascadeDetach' => false,
'sourceToTargetKeyColumns' => array('foo_id' => 'foo_id'), 'joinColumnFieldNames' => array('foo_id' => 'foo_id'),
'targetToSourceKeyColumns' => array('foo_id' => 'foo_id')),
'oid' => '000000002ec87daf00000000461b1d81',
'newValId' => array('fooTranslationId' => '1635'), 'targetClass' => object(ClassMetadata), 'owningTable' => 'foo_category',
'joinColumn' => array('name' => 'foo_id', 'unique' => true, 'nullable' => true, 'onDelete' => null, 'columnDefinition' => null,
'referencedColumnName' => 'foo_id'), 'sourceColumn' => 'foo_id', 'targetColumn' => 'foo_id', 'quotedColumn' => 'foo_id')) in vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php line 685
更新 这些是FooTranslation的详细信息和映射:
/**
* FooTranslation
*
* @ORM\Table(name="foo_translation", indexes= {@ORM\Index(name="foo", columns={"foo_id"})})
* @ORM\Entity(repositoryClass="XXX\SomeBundle\Entity\Repository\FooTranslationRepository")
*/
class FooTranslation
{
/**
* @var integer
* @ORM\Id
* @ORM\Column(name="foo_translation_id", type="integer")
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $fooTranslationId;
/**
* @var integer
*
* @ORM\Column(name="foo_id", type="integer")
*
*/
private $fooId;
- 这些是FooCategory细节和映射:
**
* FooCategory
*
* @ORM\Table(name="foo_category")
* @ORM\Entity(repositoryClass="XXX\SomeBundle\Entity\Repository\FooCategoryRepository")
*/
class FooCategory
{
/**
* @var integer
*
* @ORM\Id
* @ORM\Column(name="foo_category_id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $fooCategoryId;
/**
* @var \XXX\SomeBundle\Entity\Category
*
* @ORM\ManyToOne(targetEntity="XXX\SomeBundle\Entity\Category")
* @ORM\JoinColumn(name="category_id", referencedColumnName="category_id")
*
*/
private $category;
希望这会有所帮助。
更新Nr2
这是实际的消息:
ContextErrorException: Notice: Undefined index: fooId in /vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php line 685
堆栈跟踪在上面。
非常感谢。
Foo_Category表:
CREATE TABLE `foo_category` (
`foo_category_id` int(11) NOT NULL AUTO_INCREMENT,
`foo_id` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`category_id` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`foo_category_id`),
KEY `foo_category_foo` (`competition_id`),
KEY `foo_category_category` (`category_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TABLE `foo_translation` (
`foo_translation_id` int(11) NOT NULL AUTO_INCREMENT,
`foo_id` int(11) NOT NULL,
`language_id` int(11) NOT NULL,
`foo` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`foo_shortname` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`section` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL,
`timestamp_add` datetime NOT NULL,
`timestamp_update` datetime DEFAULT NULL,
PRIMARY KEY (`foo_translation_id`),
KEY `foo` (`foo_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1710 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;