I have a ManyToMany
relationship defined as follow:
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;
}
If I try to add a new order I get this error:
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
Where is the error? What's wrong in my mapping?
$id
instead it is called$no_order
. Here is the definition I have ` /** * @ORM\Id * @ORM\Column(type="string", length=15, unique=true, nullable=false) */ protected $no_order;` – ReynierPM