I want to connect two entities
Dish that is in some DishCategory
Dish (category_id) with DishCategory (id)
There is an error:
The association AppBundle\Entity\Dish#categoryId refers to the inverse side field AppBundle\Entity\DishCategory#category_id which does not exist.
These are my entity classes
Dish Entity
class Dish
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
*@ORM\ManyToOne(targetEntity = "DishCategory",inversedBy="category_id",cascade={"persist"})
* @ORM\JoinColumn(name="id",referencedColumnName="id")
*/
private $categoryId;
}
DishCategory Entity
class DishCategory
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\OneToMany(targetEntity="Dish", mappedBy="category_id")
* @ORM\JoinColumn(name="category_id",referencedColumnName="id")
*/
private $id;
}
In DishController I run this function to repository
$dishes = $em->getRepository('AppBundle:Dish')->findAllAsArray();
And that how DishRepository looks
public function findAllAsArray()
{
return $q = $this->createQueryBuilder('d')
->join('d.categoryId','c')
->select('d.id as id_dish','c.id as id_cat','d.price')
->orderBy('c.position', 'asc')
->orderBy('d.position', 'asc')
->getQuery()
->getResult(Query::HYDRATE_ARRAY);
}
I have read many tutorials about OneToMany but still I cant find where is the problem :(
Still getting error:
The association AppBundle\Entity\Dish#categoryId refers to the inverse side field AppBundle\Entity\DishCategory#category_id which does not exist.
:(