[英]Symfony & Doctrine: Undefined index when trying to access one-to-many
Im having a bit of problems. 我有一些问题。 I have 2 classes: Carorder: 我有2节课:下单:
<?php
namespace AppBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use AppBundle\Entity\Orderdetail;
/**
* @ORM\Entity
* @ORM\Table(name="carorder")
*/
class Carorder
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue
*/
protected $id;
/**
* @ORM\OneToMany(targetEntity="Orderdetail", mappedBy="Carorder", cascade={"persist","remove"})
**/
protected $orderdetails;
//Then all the auto genereted setters and getters beneath here
Orderdetail: 订单详情:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/** @ORM\Entity
* @ORM\Table(name="orderdetail")
*/
class Orderdetail
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Carorder", inversedBy="orderdetails")
**/
protected $carorder;
/**
* @ORM\Column(type="integer")
*/
protected $amount;
//Then all the auto generated setters and getters beneath here
I can't access the orderdetail through the Carorder. 我无法通过Carorder访问orderdetail。 For example this example, just thorws the 例如,这个例子
Undefined index: Carorder
Example: 例:
$repository = $this->getDoctrine()->getRepository('AppBundle:Carorder');
$orders = $repository->findAll();
$orderdetail = $orders[0]->getOrderdetails()->first();
I have no idea what is causing this, so i hoped you guys could help me out. 我不知道是什么原因造成的,所以我希望你们能帮助我。
You mapped the property Carorder
but your property name is carorder
, it's case sensitive. 您已映射属性Carorder
但属性名称是carorder
,区分大小写。
A correct mapping could be: 正确的映射可能是:
/**
* @ORM\OneToMany(targetEntity="Orderdetail", mappedBy="carorder", cascade={"persist","remove"})
**/
protected $orderdetails;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.