Related
i have two entities 'Panier' and 'Reservation' i want to add a one to many foreign key (the Entity 'Panier' can have many 'Reservation' and 'Reservation' has only one 'Panier' id ) , so i have to add a foreign key 'id' of 'Panier' in my Reservation entity class .
this is my Reservation class :
class Reservation
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var \DateTime
*
* #ORM\Column(name="dateReservation", type="datetime", nullable=false)
*/
private $datereservation = 'CURRENT_TIMESTAMP';
/**
* #var integer
*
* #ORM\Column(name="quantite", type="integer", nullable=false)
*/
private $quantite;
/**
* #var float
*
* #ORM\Column(name="total", type="float", precision=10, scale=0, nullable=true)
*/
private $total;
/**
* #var string
*
* #ORM\Column(name="type", type="string", length=255, nullable=false)
*/
private $type;
/**
* #var string
*
* #ORM\Column(name="seat", type="string", length=255, nullable=false)
*/
private $seat;
/**
* #var integer
*
* #ORM\Column(name="payer", type="integer", nullable=true)
*/
private $payer;
/**
* #var string
*
* #ORM\Column(name="nomReservation", type="string", length=255, nullable=true)
*/
private $nomreservation;
/**
* #var \Event
*
* #ORM\ManyToOne(targetEntity="Event")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="event_id", referencedColumnName="id")
* })
*/
private $event;
/**
* #var \User
*
* #ORM\ManyToOne(targetEntity="User")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="user_id", referencedColumnName="id")
* })
*/
private $user;
<?php
/** #Entity */
class Reservation {
/**
* #ManyToOne(targetEntity="Panier", inversedBy="reservations")
* #JoinColumn(name="panier_id", referencedColumnName="id")
*/
private $panier;
}
/** #Entity */
class Panier {
/**
* One Panier has many Reservations. This is the inverse side.
* #OneToMany(targetEntity="Reservation", mappedBy="panier")
*/
private $reservations;
public function __construct() {
$this->features = new ArrayCollection();
}
}
I'm a Symfony beginner and been stuck on this issue for a while. I have two entities (Mairie and Ville) with a many-to-one relation. Ville is an imported table, pre-filled with info. In a form, the user creates an instance of Mairie and with the form data, it will find a Ville to bind to.
Problem is : doctrine does find a Ville object when the Mairie is created, but when I want to set it to the Mairie object, it is nulled. Here's my code, in the Controller :
if($formMairie->isSubmitted() && $formMairie->isValid())
{
$repoMairie = $this->getDoctrine()->getRepository(Mairie::class);
$repoVilles = $this->getDoctrine()->getRepository(Villes::class);
$inseeInput = $mairie->getInsee();
$ville = $repoVilles->findOneBy(array("ville_code_commune" => $inseeInput));
dump($ville);
This dump works : it finds the right instance of Ville in the database and returns an object filled with the right properties.
$mairie->setVilles($ville);
This doesn't work, the Ville property of Mairie is set to null and I get no errors when I flush.
$mairieVille = $mairie->getVilles();
dump($mairieVille);
Returns null.
Why isn't the object registered ? I thought this could be an SQL issue since I've imported the Ville table but I can't find anything. I have used this method to bind other entities together and I've had no issue until now... Here are my two entities for more info (getters and setters not included) :
Ville:
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Villes
*
* #ORM\Table(name="villes")
* #ORM\Entity
*/
class Villes
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var int
*
* #ORM\Column(name="ville_id", type="integer", nullable=false)
*/
private $ville_id;
/**
* #var string|null
*
* #ORM\Column(name="ville_departement", type="string", length=3, nullable=true)
*/
private $ville_departement;
/**
* #var string|null
*
* #ORM\Column(name="ville_slug", type="string", length=255, nullable=true)
*/
private $ville_slug;
/**
* #var string|null
*
* #ORM\Column(name="ville_nom", type="string", length=45, nullable=true)
*/
private $ville_nom;
/**
* #var string|null
*
* #ORM\Column(name="ville_nom_simple", type="string", length=45, nullable=true)
*/
private $ville_nom_simple;
/**
* #var string|null
*
* #ORM\Column(name="ville_nom_reel", type="string", length=45, nullable=true)
*/
private $ville_nom_reel;
/**
* #var string|null
*
* #ORM\Column(name="ville_nom_soundex", type="string", length=20, nullable=true)
*/
private $ville_nom_soundex;
/**
* #var string|null
*
* #ORM\Column(name="ville_nom_methaphone", type="string", length=22, nullable=true)
*/
private $ville_nom_methaphone;
/**
* #var string|null
*
* #ORM\Column(name="ville_code_postal", type="string", length=255, nullable=true)
*/
private $ville_code_postal;
/**
* #var string|null
*
* #ORM\Column(name="ville_commune", type="string", length=3, nullable=true)
*/
private $ville_commune;
/**
* #var string
*
* #ORM\Column(name="ville_code_commune", type="string", length=5, nullable=false)
*/
private $ville_code_commune;
/**
* #var int|null
*
* #ORM\Column(name="ville_arrondissement", type="integer", nullable=true)
*/
private $ville_arrondissement;
/**
* #var string|null
*
* #ORM\Column(name="ville_canton", type="string", length=4, nullable=true)
*/
private $ville_canton;
/**
* #var int|null
*
* #ORM\Column(name="ville_amdi", type="integer", nullable=true)
*/
private $ville_amdi;
/**
* #var int|null
*
* #ORM\Column(name="ville_population_2010", type="integer", nullable=true)
*/
private $ville_population_2010;
/**
* #var int|null
*
* #ORM\Column(name="ville_population_1999", type="integer", nullable=true)
*/
private $ville_population_1999;
/**
* #var int|null
*
* #ORM\Column(name="ville_population_2012", type="integer", nullable=true)
*/
private $ville_population_2012;
/**
* #var int|null
*
* #ORM\Column(name="ville_densite_2010", type="integer", nullable=true)
*/
private $ville_densite_2010;
/**
* #var float|null
*
* #ORM\Column(name="ville_surface", type="float", precision=10, scale=0, nullable=true)
*/
private $ville_surface;
/**
* #var float|null
*
* #ORM\Column(name="ville_longitude_deg", type="float", precision=10, scale=0, nullable=true)
*/
private $ville_longitude_deg;
/**
* #var float|null
*
* #ORM\Column(name="ville_latitude_deg", type="float", precision=10, scale=0, nullable=true)
*/
private $ville_latitude_deg;
/**
* #var string|null
*
* #ORM\Column(name="ville_longitude_grd", type="string", length=9, nullable=true)
*/
private $ville_longitude_grd;
/**
* #var string|null
*
* #ORM\Column(name="ville_latitude_grd", type="string", length=8, nullable=true)
*/
private $ville_latitude_grd;
/**
* #var string|null
*
* #ORM\Column(name="ville_longitude_dms", type="string", length=9, nullable=true)
*/
private $ville_longitude_dms;
/**
* #var string|null
*
* #ORM\Column(name="ville_latitude_dms", type="string", length=8, nullable=true)
*/
private $ville_latitude_dms;
/**
* #var int|null
*
* #ORM\Column(name="ville_zmin", type="integer", nullable=true)
*/
private $ville_zmin;
/**
* #var int|null
*
* #ORM\Column(name="ville_zmax", type="integer", nullable=true)
*/
private $ville_zmax;
Mairie
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Mairie
*
* #ORM\Table(name="mairie", uniqueConstraints={#ORM\UniqueConstraint(name="UNIQ_3946A254A73F0036", columns={"ville_id"})}, indexes={#ORM\Index(name="IDX_3946A254CF94313", columns={"office_tourisme_id"})})
* #ORM\Entity
*/
class Mairie
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var string|null
*
* #ORM\Column(name="mairie_nom_touristique", type="string", length=255, nullable=true)
*/
private $mairieNomTouristique;
/**
* #var string|null
*
* #ORM\Column(name="mairie_descriptif_1", type="string", length=255, nullable=true)
*/
private $mairieDescriptif1;
/**
* #var string|null
*
* #ORM\Column(name="mairie_descriptif_2", type="string", length=255, nullable=true)
*/
private $mairieDescriptif2;
/**
* #var string|null
*
* #ORM\Column(name="mairie_epci_rattachement", type="string", length=255, nullable=true)
*/
private $mairieEpciRattachement;
/**
* #var string
*
* #ORM\Column(name="mairie_maire_nom", type="string", length=255, nullable=false)
*/
private $mairieMaireNom;
/**
* #var string
*
* #ORM\Column(name="mairie_maire_prenom", type="string", length=255, nullable=false)
*/
private $mairieMairePrenom;
/**
* #var string|null
*
* #ORM\Column(name="mairie_adjoint_nom", type="string", length=255, nullable=true)
*/
private $mairieAdjointNom;
/**
* #var string|null
*
* #ORM\Column(name="mairie_adjoint_prenom", type="string", length=255, nullable=true)
*/
private $mairieAdjointPrenom;
/**
* #var string|null
*
* #ORM\Column(name="mairie_contact_nom", type="string", length=255, nullable=true)
*/
private $mairieContactNom;
/**
* #var string|null
*
* #ORM\Column(name="mairie_contact_prenom", type="string", length=255, nullable=true)
*/
private $mairieContactPrenom;
/**
* #var int
*
* #ORM\Column(name="mairie_telephone_contact", type="integer", nullable=false)
*/
private $mairieTelephoneContact;
/**
* #var string
*
* #ORM\Column(name="mairie_email_contact", type="string", length=255, nullable=false)
*/
private $mairieEmailContact;
/**
* #var string
*
* #ORM\Column(name="mairie_latitude", type="string", length=255, nullable=false)
*/
private $mairieLatitude;
/**
* #var string
*
* #ORM\Column(name="mairie_longitude", type="string", length=255, nullable=false)
*/
private $mairieLongitude;
/**
* #var string|null
*
* #ORM\Column(name="mairie_photo_1", type="string", length=255, nullable=true)
*/
private $mairiePhoto1;
/**
* #var string|null
*
* #ORM\Column(name="mairie_photo_2", type="string", length=255, nullable=true)
*/
private $mairiePhoto2;
/**
* #var string|null
*
* #ORM\Column(name="mairie_photo_3", type="string", length=255, nullable=true)
*/
private $mairiePhoto3;
/**
* #var string|null
*
* #ORM\Column(name="mairie_photo_4", type="string", length=255, nullable=true)
*/
private $mairiePhoto4;
/**
* #var string|null
*
* #ORM\Column(name="mairie_taxe_sejour_gestionnaire", type="string", length=255, nullable=true)
*/
private $mairieTaxeSejourGestionnaire;
/**
* #var string|null
*
* #ORM\Column(name="mairie_taxe_sejour_bareme", type="string", length=255, nullable=true)
*/
private $mairieTaxeSejourBareme;
/**
* #var string|null
*
* #ORM\Column(name="mairie_sejour_lien", type="string", length=255, nullable=true)
*/
private $mairieSejourLien;
/**
* #var string|null
*
* #ORM\Column(name="mairie_contact_nom_prenom", type="string", length=255, nullable=true)
*/
private $mairieContactNomPrenom;
/**
* #var string|null
*
* #ORM\Column(name="mairie_de_telephone", type="text", length=255, nullable=true)
*/
private $mairieDeTelephone;
/**
* #var string|null
*
* #ORM\Column(name="mairie_sejour_email", type="string", length=255, nullable=true)
*/
private $mairieSejourEmail;
/**
* #var string|null
*
* #ORM\Column(name="mairie_rappel_texte", type="string", length=255, nullable=true)
*/
private $mairieRappelTexte;
/**
* #var string|null
*
* #ORM\Column(name="mairie_rappel_lien", type="string", length=255, nullable=true)
*/
private $mairieRappelLien;
/**
* #var string|null
*
* #ORM\Column(name="mairie_logo", type="string", length=255, nullable=true)
*/
private $mairieLogo;
/**
* #var string|null
*
* #ORM\Column(name="mairie_logo_2", type="string", length=255, nullable=true)
*/
private $mairieLogo2;
/**
* #var \DateTime
*
* #ORM\Column(name="mairie_date_inscription", type="datetime", nullable=false)
*/
private $mairieDateInscription;
/**
* #var string|null
*
* #ORM\Column(name="mairie_tampon", type="string", length=255, nullable=true)
*/
private $mairieTampon;
/**
* #var string|null
*
* #ORM\Column(name="mairie_maire_signature", type="string", length=255, nullable=true)
*/
private $mairieMaireSignature;
/**
* #var string
*
* #ORM\Column(name="mairie_slug", type="string", length=255, nullable=false)
*/
private $mairieSlug;
/**
* #var string
*
* #ORM\Column(name="insee", type="string", length=255, nullable=false)
*/
private $insee;
/**
* #var string
*
* #ORM\Column(name="mairie_adresse", type="string", length=255, nullable=false)
*/
private $mairieAdresse;
/**
* #var string|null
*
* #ORM\Column(name="mairie_complement_adresse", type="string", length=255, nullable=true)
*/
private $mairieComplementAdresse;
/**
* #var string
*
* #ORM\Column(name="mairie_postal_code", type="string", length=10, nullable=false)
*/
private $mairiePostalCode;
/**
* #var string
*
* #ORM\Column(name="mairie_commune", type="string", length=255, nullable=false)
*/
private $mairieCommune;
/**
* #var \Villes
*
* #ORM\ManyToOne(targetEntity="Villes")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="ville_id", referencedColumnName="id")
* })
*/
private $ville;
/**
* #var \OfficeTourisme
*
* #ORM\ManyToOne(targetEntity="OfficeTourisme")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="office_tourisme_id", referencedColumnName="id")
* })
*/
private $officeTourisme;
public function __construct()
{
$this->user_id_heb = new ArrayCollection();
$this->hebergements = new ArrayCollection();
$this->mairie_id_user = new ArrayCollection();
$this->user = new ArrayCollection();
$this->hebergement = new ArrayCollection();
}
public function getVilles(): ?Villes
{
return $this->ville;
}
public function setVilles(?Villes $villes): self
{
$this->villes = $villes;
return $this;
}
In Mairie :
The function setVilles
public function setVilles(?Villes $villes): self
{
$this->villes = $villes;
return $this;
}
Should'nt it be :
$this->ville = $ville;
Because the property "Villes" with an S doesn't seem to exist.
So the function should be :
public function setVille(?Ville $ville): self
{
$this->ville = $ville;
return $this;
}
Your setVilles() function is seting $this->villes rather than $this->ville
I'm facing a big problem with Doctrine when i'm requesting a table with a composite primary key referencing foreign keys.
I have a 3 entities:
Library(idLibrary,adress), Book(idBook,title,pageCount), Container(idLibrary,idBook, quantity).
Everything is generated without any errors but when i'm doing findAll() request on my Container repository my browser freezes and nothing is showed like it was stuck in a loop (there 3 rows in my Container table).
class Bibliotheque
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\Column(name="name", type="string", length=60)
*/
private $name;
/**
* #ORM\Column(name="adress", type="string", length=60)
*/
private $adress;
}
class Conteneur
{
/**
* Many Containers have One library.
* #ORM\Id
* #ORM\OneToOne(targetEntity="Bibliotheque")
* #ORM\JoinColumn(name="libraryId", referencedColumnName="id")
*/
private $library;
/**
* One Container has One book.
* #ORM\Id
* #ORM\OneToOne(targetEntity="Livre")
* #ORM\JoinColumn(name="bookId", referencedColumnName="id")
*/
private $book;
/**
* #ORM\Column(name="quantity", type="integer")
*/
private $quantity;
}
class Livre
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* #ORM\Column(name="pageCount", type="integer")
*/
private $pageCount;
/**
* Un livre a plusieurs auteurs
* #ORM\ManyToMany(targetEntity="Auteur")
* #ORM\JoinTable(name="books_authors",
* joinColumns={#ORM\JoinColumn(name="book_id", referencedColumnName="id")},
* inverseJoinColumns={#ORM\JoinColumn(name="author_id", referencedColumnName="id")}
* )
*/
private $authors;
}
class Auteur
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\Column(name="name", type="string", length=60)
*/
private $name;
/**
* #ORM\Column(name="surname", type="string", length=60)
*/
private $prenom;
/**
* #ORM\Column(name="birthDate", type="date")
*/
private $birthDate;
}
firstly, please use only French or English for class name and variable.
Add id inside class "Container" and remove annotation #ORM\id for attributes "library" and "book"
Define attribute "authors" with ArrayCollection and add method getAuthors(), addAuthor(Author $author), removeAuthor(Author $author)
And rename the tables name => "name_id" not "nameId"
look documention http://symfony.com/doc/current/doctrine.html
class Library
{
/**
* #var integer $id
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string $name
*
* #ORM\Column(name="name", type="string", length=60)
*/
private $name;
/**
* #var string $address
*
* #ORM\Column(name="address", type="string", length=60)
*/
private $address;
}
class Container
{
/**
* #var integer $id
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* Many Containers have One library.
*
* #ORM\OneToOne(targetEntity="Library")
* #ORM\JoinColumn(name="library_id", referencedColumnName="id")
*/
private $library;
/**
* One Container has One book.
*
* #ORM\OneToOne(targetEntity="Book")
* #ORM\JoinColumn(name="book_id", referencedColumnName="id")
*/
private $book;
/**
* #ORM\Column(name="quantity", type="integer")
*/
private $quantity;
}
class Book
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string $title
*
* #ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* #var string $pageCount
*
* #ORM\Column(name="page_count", type="integer")
*/
private $pageCount;
/**
* A book have many authors
*
* #var ArrayCollection $authors
*
* #ORM\ManyToMany(targetEntity="Auteur")
* #ORM\JoinTable(name="books_authors",
* joinColumns={#ORM\JoinColumn(name="book_id", referencedColumnName="id")},
* inverseJoinColumns={#ORM\JoinColumn(name="author_id", referencedColumnName="id")}
* )
*/
private $authors;
/**
* #return ArrayCollection
*/
public function getAuthors()
{
return $this->authors;
}
/**
* #param Author $author
*
* #return $this
*/
public function addAuthor(Author $author)
{
$this->authors->add($author);
return $this;
}
/**
* #param Author $author
*
* #return $this
*/
public function removeAuthor(Author $author)
{
$this->authors->removeElement($author);
return $this;
}
}
class Author
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string $firstname
*
* #ORM\Column(name="firstname", type="string", length=60)
*/
private $firstname;
/**
* #var string $lastname
*
* #ORM\Column(name="lastname", type="string", length=60)
*/
private $lastname;
/**
* #var DateTime $birthDate
*
* #ORM\Column(name="birthDate", type="date")
*/
private $birthDate;
}
I have a problem with two entities in Symfony2 with Doctrine:
This is the first Entity:
/**
* Pedidos
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="RestCarta\Bundle\FrontendBundle\Entity\PedidosRepository")
*/
class Pedidos
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="usuario", type="string", length=100)
*/
private $usuario;
/**
* #var string
*
* #ORM\Column(name="mesa", type="string", length=3)
*/
private $mesa;
/**
* #var integer
*
* #ORM\OneToOne(targetEntity="Articulos")
* #ORM\JoinColumn(name="articulo_id", referencedColumnName="id")
*/
private $articulo;
/**
* #var string
*
* #ORM\Column(name="precio", type="decimal")
*/
private $precio;
This is the second Entity:
/**
* Articulos
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="RestCarta\Bundle\FrontendBundle\Entity\ArticulosRepository")
*/
class Articulos
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="referencia", type="string", length=100)
*/
private $referencia;
/**
* #var string
*
* #ORM\Column(name="nombre", type="string", length=255)
*/
private $nombre;
/**
* #var string
*
* #ORM\Column(name="descripcion", type="string", length=255)
*/
private $descripcion;
/**
* #var string
*
* #ORM\Column(name="precio", type="decimal")
*/
private $precio;
/**
* #var string
*
* #ORM\Column(name="imagen", type="string", length=255)
*/
private $imagen;
/**
* #ORM\ManyToOne(targetEntity="Categorias", inversedBy="articulos")
* #ORM\JoinColumn(name="categoria_id", referencedColumnName="id")
*/
protected $categoria;
And now the problem.
How i can persist one "Pedido" with contain one "Articulo" ??
I can read all "Pedido" and the LEFT JOIN with "Articulo" work perfectly, (data inserted manually via phpMyAdmin) but when I persist more data with this code:
$em = $this->getDoctrine()->getManager();
$pedido = new Pedidos();
$pedido->setUsuario('blablabla');
$pedido->setMesa('blablabla');
$pedido->setArticulo($identi);
$pedido->setPrecio('blablabla');
$em->persist($pedido);
$em->flush();
$identi = corresponds to an id of "Articulos"
The result is:
Warning: spl_object_hash() expects parameter 1 to be object, string
given in
/Applications/MAMP/htdocs/RestCarta/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php
line 1388 500 Internal Server Error - ContextErrorException
Please, anyone can help me?
Thanks in Advance
$identi must be a entity object, not only the ID you can use
$em->getReference('YourNamespace\Articulos', $identi);
Does anyone have a clue why in the world I would be getting 20 minute page load times in dev in Symfony2? It just randomly happens to me. One day I will get fast load times, the next day I am twiddling my thumbs waiting for a page to load. What can I check/disable/enable/etc? Thanks!
Here is my latest page load:
Time: 298068 ms
Here is the Entity for PurchaseOrder
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="archived_po_number", type="string", length=50, nullable=true)
* #Common\Versioned
*/
private $archived_po_number;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=50, nullable=true)
* #Common\Versioned
*/
private $name;
/**
* #var string
*
* #ORM\Column(name="show_locations", type="string", length=1, nullable=true)
* #Common\Versioned
*/
private $show_locations;
/**
* #var integer
*
* #ORM\Column(name="freight", type="decimal", precision=10, scale=2, nullable=true)
* #Common\Versioned
*/
private $freight;
/**
* #var integer
*
* #ORM\Column(name="pallets", type="integer", nullable=true)
* #Common\Versioned
*/
private $pallets;
/**
* #var integer
*
* #ORM\Column(name="boxes", type="integer", nullable=true)
* #Common\Versioned
*/
private $boxes;
/**
* #var text
* #ORM\Column(name="internal_notes", type="text", nullable=true)
* #Common\Versioned
*/
private $internal_notes;
/**
* #var text
* #ORM\Column(name="sales_rep_notes", type="text", nullable=true)
* #Common\Versioned
*/
private $sales_rep_notes;
/**
* #var string
*
* #ORM\Column(name="custom_purchase_order_number", type="string", length=255, nullable=true)
* #Common\Versioned
*/
private $custom_purchase_order_number;
/**
* #ORM\ManyToOne(targetEntity="WIC\CommonBundle\Entity\CustomOptions", inversedBy="purchaseOrders")
* #ORM\JoinColumn(name="purchase_order_class", referencedColumnName="id", nullable=true)
* #Common\Versioned
*/
private $purchase_order_class;
/**
* #ORM\ManyToOne(targetEntity="WIC\WarehouseBundle\Entity\Warehouse", inversedBy="purchaseOrders")
* #ORM\JoinColumn(name="generated_by_location", referencedColumnName="id", nullable=true)
* #Common\Versioned
*/
private $generated_by_location;
/**
* #ORM\ManyToOne(targetEntity="WIC\InventoryLocationBundle\Entity\InventoryLocation", inversedBy="purchaseOrders")
* #ORM\JoinColumn(name="receive_location", referencedColumnName="id", nullable=true)
* #Common\Versioned
*/
private $receive_location;
/**
* #ORM\ManyToOne(targetEntity="WIC\WarehouseBundle\Entity\Warehouse", inversedBy="purchaseOrders")
* #ORM\JoinColumn(name="company_name", referencedColumnName="id", nullable=true)
* #Common\Versioned
*/
private $company_name;
/**
* #ORM\ManyToOne(targetEntity="WIC\WarehouseBundle\Entity\Warehouse", inversedBy="purchaseOrders")
* #ORM\JoinColumn(name="ship_to", referencedColumnName="id", nullable=true)
* #Common\Versioned
*/
private $ship_to;
/**
* #ORM\ManyToOne(targetEntity="WIC\WarehouseBundle\Entity\Warehouse", inversedBy="purchaseOrders")
* #ORM\JoinColumn(name="bill_to", referencedColumnName="id", nullable=true)
* #Common\Versioned
*/
private $bill_to;
/**
* #ORM\ManyToOne(targetEntity="WIC\CommonBundle\Entity\CustomOptions", inversedBy="purchaseOrders")
* #ORM\JoinColumn(name="payment_terms", referencedColumnName="id", nullable=true)
* #Common\Versioned
*/
private $payment_terms;
/**
* #ORM\ManyToOne(targetEntity="WIC\CommonBundle\Entity\CustomOptions", inversedBy="purchaseOrders")
* #ORM\JoinColumn(name="fob", referencedColumnName="id", nullable=true)
* #Common\Versioned
*/
private $fob;
/**
* #ORM\ManyToOne(targetEntity="WIC\CommonBundle\Entity\CustomOptions", inversedBy="purchaseOrders")
* #ORM\JoinColumn(name="ship_via", referencedColumnName="id", nullable=true)
* #Common\Versioned
*/
private $ship_via;
/**
* #var datetime
*
* #ORM\Column(name="ship_by", type="datetime", nullable=true)
* #Common\Versioned
*/
private $ship_by;
/**
* #var datetime
*
* #ORM\Column(name="cancel_by", type="datetime", nullable=true)
* #Common\Versioned
*/
private $cancel_by;
/**
* #var datetime
*
* #ORM\Column(name="due_by", type="datetime", nullable=true)
* #Common\Versioned
*/
private $due_by;
/**
* #var string
*
* #ORM\Column(name="nbt", type="string", length=2, nullable=true)
* #Common\Versioned
*/
private $nbt;
/**
* #ORM\OneToMany(targetEntity="WIC\PurchaseOrderLineItemBundle\Entity\PurchaseOrderLineItem", mappedBy="purchaseOrder", cascade={"remove"}, fetch="EAGER")
*/
protected $purchaseOrderLineItem;
/**
* #ORM\OneToMany(targetEntity="WIC\PurchaseOrderBundle\Entity\PurchaseOrderCharge", mappedBy="purchaseOrder", cascade={"remove"}, fetch="EAGER")
*/
protected $purchaseOrderCharge;
/**
* #ORM\OneToMany(targetEntity="WIC\PurchaseOrderBundle\Entity\PurchaseOrderPayment", mappedBy="purchaseOrder", cascade={"remove"}, fetch="EAGER")
*/
protected $purchaseOrderPayment;
/**
* #ORM\ManyToOne(targetEntity="WIC\SupplierBundle\Entity\Supplier", inversedBy="purchaseOrders")
* #ORM\JoinColumn(name="supplier_id", referencedColumnName="id", nullable=true)
* #Common\Versioned
*/
protected $supplier;
/**
* #ORM\ManyToOne(targetEntity="WIC\CommonBundle\Entity\CustomOptions", inversedBy="purchaseOrders")
* #ORM\JoinColumn(name="status_id", referencedColumnName="id", nullable=true)
* #Common\Versioned
*/
private $status;
/**
* #ORM\ManyToOne(targetEntity="WIC\UserBundle\Entity\User")
* #ORM\JoinColumn(name="created_by", referencedColumnName="id")
* #Common\Blameable(on="create")
*/
private $createdBy;
/**
* #ORM\ManyToOne(targetEntity="WIC\UserBundle\Entity\User")
* #ORM\JoinColumn(name="updated_by", referencedColumnName="id")
* #Common\Blameable(on="update")
*/
private $updatedBy;
/**
* #ORM\ManyToOne(targetEntity="WIC\AccountBundle\Entity\Account", inversedBy="purchaseOrders")
* #ORM\JoinColumn(name="account_id", referencedColumnName="id", nullable=false)
* #Common\Versioned
* #Common\Blameable(on="create")
*/
protected $account;
/**
* #var datetime $created
*
* #Common\Timestampable(on="create")
* #ORM\Column(type="datetime")
*/
private $created;
/**
* #var datetime $updated
*
* #Common\Timestampable(on="update")
* #ORM\Column(type="datetime", nullable=true)
*/
private $updated;
/**
* #ORM\Column(name="deletedAt", type="datetime", nullable=true)
*/
private $deletedAt;
Here is my controller method listAction()
// verify access
if (false === $this->get('security.context')->isGranted('ROLE_ADMIN')) {
$classIdentity = new ObjectIdentity('class', 'WIC\\PurchaseOrderBundle\\Entity\\PurchaseOrder');
if (false === $this->get('security.context')->isGranted('VIEW', $classIdentity)) {
throw new AccessDeniedException('Only an admin user has access to this section...');
}
}
// get user's account
$account = $this->getUser()->getAccount();
$search_form = $this->createForm(new PurchaseOrderSearchType());
$em = $this->getDoctrine()->getManager();
if ($request->isMethod('POST')) {
$search_form->bind($request);
// if ($search_form->isValid()) {
$data = $search_form->getData();
$purchaseOrders = $em->getRepository('WICPurchaseOrderBundle:PurchaseOrder')->getListBy($data);
// }
} else {
if($this->get('request')->query->get('letter')){
}else{
}
// Set the up the pagination statement...
$em = $this->getDoctrine()->getManager();
$dql = "SELECT p FROM WIC\PurchaseOrderBundle\Entity\PurchaseOrder p WHERE p.account=:account_id ORDER BY p.created desc";
$query = $em->createQuery($dql);
$query->setParameters(array(
'account_id' => $account->getId(),
));
$paginator = $this->get('knp_paginator');
$paginatorObject = $paginator->paginate(
$query,
$this->get('request')->query->get('page', 1),25
);
// $purchaseOrders = $em->getRepository('WICPurchaseOrderBundle:PurchaseOrder')->findByAccount($account->getId(),array('id' => 'DESC'));
}
return array(
'heading' => 'Purchase Order',
'sidebarLeftTitle'=>'Purchase Order Menu',
'purchaseOrders' => $paginatorObject,
'search_form' => $search_form->createView(),
);
By default in app_dev.php you have the profiler bar, click on the timer and you will have a good start to debug (timeline with main/sub request, etc)
The issue was in the OneToMany relationship code where it says fetch="EAGER". This was pulling in all sorts of unnecessary associations and db queries. When I removed it, the db queries went down to 4 per page instead of 4000.
Are you using x-debug or any PHP level profiling? You've either got some form of recursion happening or one of the steps in the security\http\firewall process is taking a very long time to complete.
My suggestion would be
Look at your stack-trace and find anywhere there are highly repeated events around the security\http\firewall code and investigate if they exist
Quickly step through your code using x-debug, and find where the delay is occurring. With a few page reloads you should be able to step into the section which is causing the long page load times.
If you are using profiling, make sure your created files aren't ridiculously verbose. I've seen this long page load issue happen before due to profiling, where each page load would create a 20Gb+ profiling file.