I'm modifying CRUD generated by doctrine in symfony 2.8. I have 2 tables (proveedores(providers) and productos(products)) with a relation 1:n. I want show through index action the complete list of products with their providers that it owns. What I try is create a DQL sentence that joins the 2 tables in the result and then manipulate it with twig. When I try to access to index, I get the error mentioned.
[Semantical Error] line 0, col 75 near 'x ': Error: Class Cocina\ComprasBundle\Entity\Productos has no association named proveedores
[2/2] QueryException: [Semantical Error] line 0, col 75 near 'x ': Error: Class Cocina\ComprasBundle\Entity\Productos has no association named proveedores
[1/2] QueryException: SELECT p,x FROM ComprasBundle:Productos p JOIN p.proveedores x
I have revised another similar threads over here but I have no found solution. I have checked too clearing all the doctrine caches and symfony cache but nothing. Thanks for the answers.
ENTITY PROVEEDORES
namespace Cocina\ComprasBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Proveedores
*
* @ORM\Table(name="proveedores")
* @ORM\Entity(repositoryClass="Cocina\ComprasBundle\Repository\ProveedoresRepository")
*/
class Proveedores
{
private $id;
/**
* @var string
*
* @ORM\Column(name="nombre", type="string", length=255, unique=true)
...
}
ENTITY PRODUCTOS
namespace Cocina\ComprasBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Productos
*
* @ORM\Table(name="productos")
* @ORM\Entity(repositoryClass="Cocina\ComprasBundle\Repository\ProductosRepository")
*/
class Productos
{
/**
* @var integer $idProveedor
* @ORM\ManyToOne(targetEntity="Proveedores")
* @ORM\JoinColumn(name="id_proveedor_id", referencedColumnName="id")
*/
private $idProveedor;
...
}
PRODUCTOS REPOSITORY
namespace Cocina\ComprasBundle\Repository;
use Doctrine\ORM\EntityRepository;
/**
* ProductosRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class ProductosRepository extends EntityRepository
{
public function findListaProductos()
{
$em=$this->getEntityManager();
$consulta=$em->createQuery('
SELECT p,x
FROM ComprasBundle:Productos p
JOIN p.proveedores x
');
return $consulta->getResult();
}
}
CONTROLLER
namespace Cocina\ComprasBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Cocina\ComprasBundle\Entity\Productos;
use Cocina\ComprasBundle\Form\ProductosType;
/**
* Productos controller.
*
*/
class ProductosController extends Controller
{
/**
* Lists all Productos entities.
*
*/
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
//$productos = $em->getRepository('ComprasBundle:Productos')->findAll();
$productos=$em->getRepository('ComprasBundle:Productos')->findListaProductos()->getResult();
return $this->render('ComprasBundle:productos:index.html.twig', array(
'productos' => $productos,
));
}
Productosrename the attribute$idProveedorwith$proveedores- Matteo