gpt4 book ai didi

php - 未定义索引 "order",映射错误?

转载 作者:可可西里 更新时间:2023-11-01 00:21:16 27 4
gpt4 key购买 nike

我有一个 ManyToMany 关系定义如下:

OrderHasMedia.php

/**
* @ORM\Entity
* @ORM\Table(name="order_has_media__media")
*/
class OrderHasMedia {

/**
* @ORM\Id
* @ORM\ManyToOne(targetEntity="PL\OrderBundle\Entity\Order", inversedBy="order_document", cascade={"all"})
*/
protected $order;

/**
* @ORM\Id
* @ORM\ManyToOne(targetEntity="Application\Sonata\MediaBundle\Entity\Media", inversedBy="order_document", cascade={"all"})
*/
protected $media;

}

Order.php

/**
* @ORM\Entity
* @ORM\Table(name="tb_order")
* @Gedmo\Loggable
*/
class Order {

/**
* @ORM\OneToMany(targetEntity="PL\OrderBundle\Entity\OrderHasMedia", mappedBy="order" , cascade={"all"})
*/
protected $order_document;

}

Media.php

class Media extends BaseMedia {

/**
* @var Collection
* @ORM\OneToMany(targetEntity="PL\OrderBundle\Entity\OrderHasMedia", mappedBy="media", cascade={"all"})
*
*/
protected $order_document;

}

如果我尝试添加新订单,我会收到此错误:

ContextErrorException: Notice: Undefined index: id in /var/www/html/apps/portal_de_logistica/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php line 685

in /var/www/html/apps/portal_de_logistica/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php line 685
at ErrorHandler->handle('8', 'Undefined index: id', '/var/www/html/apps/portal_de_logistica/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php', '685', array('entity' => object(OrderHasMedia), 'result' => array(), 'uow' => object(UnitOfWork), 'versioned' => null, 'field' => 'order', 'change' => array(null, object(Order)), 'newVal' => object(Order), 'assoc' => array('fieldName' => 'order', 'id' => true, 'joinColumns' => array(array('name' => 'order_id', 'referencedColumnName' => 'id')), 'cascade' => array('remove', 'persist', 'refresh', 'merge', 'detach'), 'inversedBy' => 'order_document', 'targetEntity' => 'PL\OrderBundle\Entity\Order', 'fetch' => '2', 'type' => '2', 'mappedBy' => null, 'isOwningSide' => true, 'sourceEntity' => 'PL\OrderBundle\Entity\OrderHasMedia', 'isCascadeRemove' => true, 'isCascadePersist' => true, 'isCascadeRefresh' => true, 'isCascadeMerge' => true, 'isCascadeDetach' => true, 'sourceToTargetKeyColumns' => array('order_id' => 'id'), 'joinColumnFieldNames' => array('order_id' => 'order_id'), 'targetToSourceKeyColumns' => array('id' => 'order_id'), 'orphanRemoval' => false), 'oid' => '000000005c17f96200007f239e737d4c', 'newValId' => array('no_order' => '3424'), 'targetClass' => object(ClassMetadata), 'owningTable' => 'order_has_media__media', 'joinColumn' => array('name' => 'order_id', 'referencedColumnName' => 'id'), 'sourceColumn' => 'order_id', 'targetColumn' => 'id', 'quotedColumn' => 'order_id')) in /var/www/html/apps/portal_de_logistica/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php line 685

错在哪里?我的映射有什么问题?

最佳答案

经过几个小时的头痛,我终于找到了我的错误所在,我想分享一下,以防其他人遇到同样的问题。解决方案是将 @ORM\JoinColumn() 添加到注释中,所以我现在的代码,仅针对 OrderHasMedia 实体如下:

/**
* @var Order
* @ORM\Id
* @ORM\ManyToOne(targetEntity="PL\OrderBundle\Entity\Order", inversedBy="order_document", cascade={"all"})
* @ORM\JoinColumn(name="order_no_order", referencedColumnName="no_order")
*/
protected $order;

/**
* @var Media
* @ORM\Id
* @ORM\ManyToOne(targetEntity="Application\Sonata\MediaBundle\Entity\Media", inversedBy="order_document", cascade={"all"})
* @ORM\JoinColumn(name="media__media_id", referencedColumnName="id")
*/
protected $media;

这就解决了问题。希望这会帮助其他人

关于php - 未定义索引 "order",映射错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22115397/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com