Ich modifiziere CRUD erstellt von Doktrin in Symfony 2.8. Ich habe 2 Tabellen (provedores (Anbieter) und productos (Produkte)) mit einer Beziehung 1: n. Ich möchte durch die Indexaktion die vollständige Liste der Produkte mit ihren Anbietern zeigen, die es besitzt. Was ich versuche, ist ein DQL-Satz zu erstellen, der die 2 Tabellen im Ergebnis verbindet und dann mit Zweig bearbeiten. Wenn ich versuche, auf den Index zuzugreifen, bekomme ich den Fehler erwähnt.Doktrin symfony2 Fehler: Klasse Cocina ComprasBundle Entity Productos hat keine Zuordnung namens proveedores
[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
Ich habe eine andere ähnliche Threads überarbeitet hier aber ich habe keine Lösung gefunden. Ich habe auch alle Doktrin-Caches und Symfony-Cache gelöscht, aber nichts. Danke für die Antworten.
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,
));
}
In der Klasse 'Productos' umbenennen das Attribut' $ idProveedor' mit '$ proveedores' – Matteo