Self JOIN query with Symfony entity - symfony

Here's my table :
My Category entity (without getter/setter):
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* #var string
*
* #ORM\Column(name="slug", type="string", length=255, nullable=true)
*/
private $slug;
/**
* #var int
* #Gedmo\TreeLeft
* #ORM\Column(name="lft", type="integer")
*/
private $lft;
/**
* #var int
* #Gedmo\TreeLevel
* #ORM\Column(name="lvl", type="integer")
*/
private $lvl;
/**
* #var int
* #Gedmo\TreeRight
* #ORM\Column(name="rgt", type="integer")
*/
private $rgt;
/**
* #Gedmo\TreeRoot
* #ORM\ManyToOne(targetEntity="Category")
* #ORM\JoinColumn(name="root", referencedColumnName="id", onDelete="CASCADE")
*/
private $root;
/**
* #Gedmo\TreeParent
* #ORM\ManyToOne(targetEntity="Category", inversedBy="children")
* #ORM\JoinColumn(name="parent", referencedColumnName="id", onDelete="CASCADE")
*/
private $parent;
/**
* #ORM\OneToMany(targetEntity="Category", mappedBy="parent")
* #ORM\OrderBy({"lft" = "ASC"})
*/
private $children;
In my controller, if I do this :
$category= $this->container->get('app.category.manager')->getCategoryBySlug($category_slug);
$root = $term->getRoot();
Doctrine execute 2 queries, one for the category itself, and one for the root of the category. I would like to create my own repository function to join the 2 entities in one query. I've tried so many things with the query builder, now I'm completly lost.

First, create a custom Repository class for your entity.
Then, paste the a method like the following into:
class CategoryRepository extends EntityRepository
{
public function getRootByCategorySlug($slug)
{
return $this->getEntityManager()
->createQueryBuilder()
->from('YourBundle:Category', 'c')
->where('c.slug = :slug')
->setParameter('slug', $slug)
->leftJoin('c.root', 'r') // Join the association
->select('r') // Fetch the association only
->getQuery()
->getResult()
;
}
}
And use it like follows:
$repo = $this->getDoctrine()->getManager()->getRepository('YourBundle:Category');
$rootCategory = $repo->getRootByCategorySlug('your_slug');

Related

How to get categories and sub categories in sel referencing many to one relation symfony 3

I have this entity
class Category
{
/**
* #var int
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* #ORM\OneToMany(targetEntity="AppBundle\Entity\Product",mappedBy="category")
*/
private $products;
/**
* #var int
* #ORM\Column(name="orderNr",type="integer")
*/
private $order;
/**
* #ORM\OneToMany(targetEntity="Category", mappedBy="parent")
*/
private $children;
/**
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\Category",inversedBy="children")
* #ORM\JoinColumn(name="parent_id", referencedColumnName="id")
*/
private $parent;
I want to make a query to get all categories and for each category, the childrens.
I tried many versions of queryes from other questions, but nothing seems to work.
Can anyone help me,please?
In the end i need something like this
[Category Parent 1]
[Childrens]
[0]
//details
[1]
//details

Use php-imap classes to parse new mails from server, with Symfony 2.7

I'm working on Symfony 2.7. I have to create a mail client to retrieve and send mails from the mail server (IMAP protocol); to do this, I used the php-imap classes, with a bundle (included with composer). But I'm not sure about the way I should use them : Do I extend the classes to represent my Mail and Mailbox objects, or should I create new classes from scratch ?
I don't want to manipulate IMAP straight from my controllers, I think it would be too long to process. Is that right?
Is it a good idea to create a "watcher" (periodic command executed by cron) to parse new mails every 2 minutes or so, create new mails entity from them, and send the waiting ones?
Could I do that while extending the php-imap classes? This way I would use one class only? But wouldn't that be too heavy to store for the database ?
What's the correct way to fetch only new mails ? Do I have to use a specific function, like imap_check, or do I do that by a search criteria (like date from the last check) ? I tried with criteria "NEW", but that was unsuccessful.
Also, the mailboxes I have to parse are quite heavy. I tried to make a search in one of them with "ALL" criteria, but it's really long to process ! Am I doing it right ? Do I just have to be patient ?
Here's what I did for the "watcher" function :
use PhpImap\Mailbox as ImapMailbox;
class GetNewMailsCommand extends ContainerAwareCommand
{
$em = $this->getContainer()->get('doctrine')->getEntityManager();
$mailboxes = $em->getRepository('MIPMailBundle:MailBox')->findAllActive();
foreach ($mailboxes as $mailbox){
$imapBox = new ImapMailbox('{'.$mailbox->getServer().':143/notls/norsh/novalidate-cert}INBOX', $mailbox->getAdress(), $mailbox->getPassword());
if ($mailbox->getMails() == null || empty($mailbox->getMails())){
$mailsIds = $imapBox->searchMailbox('ALL');
if(!$mailsIds) {
$output->writeln($mailbox->getAdress() . " is empty");
}
} else {
$mailsIds = $imapBox->searchMailbox('NEW');
if(!$mailsIds) {
$output->writeln("No new mail for " . $mailbox->getAdress());
}
}
foreach ($mailsIds as $mailId){
$imapMail = $imapBox->getMail($mailId);
$mail = new Mail($mailbox, false);
$mail->setSubject($imapMail->subject);
$mail->setSender($imapMail->fromAddress);
$mail->setCc($imapMail->cc);
$mail->setBcc($imapMail->bcc);
$mail->setToString($imapMail->toString);
$mail->setContent($imapMail->textPlain);
$mail->setDate(new \DateTime($imapMail->date));
foreach ($imapMail->to as $toAddress){
$mail->addRecipient($toAddress);
}
$em->persist($mail);
}
}
$em->flush();
And here's my entities :
class MailBox
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var
*
* #ORM\OneToOne(targetEntity="\MIP\CRMBundle\Entity\Agency", inversedBy="mailBox", cascade={"persist"})
* #ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=true)
*/
private $user;
/**
* #var Agency
*
* #ORM\ManyToMany(targetEntity="\MIP\CRMBundle\Entity\Agency", inversedBy="mailBoxShared")
* #ORM\JoinTable(name="mailbox_shared")
*/
private $sharedTo;
/**
* #var
*
* #ORM\OneToMany(targetEntity="Mail", mappedBy="mailBox")
*/
private $mails;
/**
* #var boolean
*
* #ORM\Column(name="active", type="boolean")
*/
private $active;
/**
* #var string
*
* #ORM\Column(name="adress", type="string", length=255)
*/
private $adress;
/**
* #var string
*
* #ORM\Column(name="server", type="string", length=255)
*/
private $server;
/**
* #var string
*
* #ORM\Column(name="password", type="string", length=255)
*/
private $password;
/**
* #var integer
*
* #ORM\Column(name="port", type="integer")
*/
private $port;
/**
* MailBox constructor.
*/
public function __construct()
{
$this->sharedTo = new ArrayCollection();
$this->mails = new ArrayCollection();
}
class Mail
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="sender", type="string", length=255)
*/
private $sender;
/**
* #var array
*
* #ORM\Column(name="recipients", type="json_array", nullable=true)
*/
private $recipients;
/**
* #var string
*
* #ORM\Column(name="toString", type="string", nullable=true)
*/
private $toString;
/**
* #var array
*
* #ORM\Column(name="cc", type="json_array", nullable=true)
*/
private $cc;
/**
* #var array
*
* #ORM\Column(name="bcc", type="json_array", nullable=true)
*/
private $bcc;
/**
* #var string
*
* #ORM\Column(name="subject", type="string", length=255, nullable=true)
*/
private $subject;
/**
* #var \DateTime
*
* #ORM\Column(name="date", type="datetime")
*/
private $date;
/**
* #var string
*
* #ORM\Column(name="content", type="text", nullable=true)
*/
private $content;
/**
* #var
*
* #ORM\OneToMany(targetEntity="MIP\CRMBundle\Entity\File", mappedBy="mail", cascade={"persist", "remove"})
* #ORM\JoinColumn(name="file_id", referencedColumnName="id", nullable=true)
*/
protected $files;
/**
* #var ArrayCollection
*/
private $attached;
/**
* #var MailBox
* #ORM\ManyToOne(targetEntity="MailBox", inversedBy="mails")
* #ORM\JoinColumn(name="mailBox_id", referencedColumnName="id")
*/
private $mailBox;
/**
* #var LabelSticker
*
* #ORM\ManyToMany(targetEntity="\MIP\MailBundle\Entity\LabelSticker", mappedBy="mails")
*/
private $labels;
/**
* #var boolean
*/
private $readed;
/**
* #var boolean
*/
private $sent;
/**
* Constructor
* #param MailBox $mailbox
* #param boolean $readed
*/
public function __construct($mailbox, $readed)
{
$this->files = new ArrayCollection();
$this->date = new \DateTime('now');
$this->mailBox = $mailbox;
$this->readed = $readed;
}
Thanks for your help !

Doctrine request crash with composite key

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;
}

Symfony2: many-to-many with extra columns no Lazy in Twig

I know, there are a lot of posts about this topic, but for me it is imposible to get the right solution.
I have 2 entities with the relationship many-to-many and in that relationship many colums (that means 3 entities). I have two questions:
The SQL is Lazy-loadinig, but I write "SELECT l, ul ...", so I want to select both tables. Why still Lazy-loading?? is There any config anywhere??
How can I show it in my Twig's Templates??
My entities are more or less like that:
Usuario:
/**
* Usuario
*
* #ORM\Table()
*/
class Usuario
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="nombre", type="string", length=255)
*/
private $nombre;
...
/**
* #ORM\OneToMany(targetEntity="UsuarioLibro", mappedBy="usuario")
*/
private $libros;
public function __construct()
{
$this->libros = new ArrayCollection();
}
...
/**
* Get libros
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getLibros()
{
return $this->libros;
}
}
Libros:
/**
* Libro
*
* #ORM\Table()
*/
class Libro
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="titulo", type="string", length=255)
*/
private $titulo;
...
/**
* #ORM\OneToMany(targetEntity="UsuarioLibro", mappedBy="libro")
*/
private $usuarios;
...
public function __construct()
{
$this->usuarios = new ArrayCollection();
}
...
/**
* Get usuarios
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getUsuarios()
{
return $this->usuarios;
}
}
UsuariosLibros (the relationship):
/**
* usuario_libro
*
* #ORM\Table(name="usuario_libro")
* #ORM\Entity
*/
class UsuarioLibro
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var integer
*
* #ORM\Column(name="tener", type="boolean", options={"default":0})
*/
private $tener;
/**
* #var integer
*
* #ORM\Column(name="leer", type="boolean", options={"default":0})
*/
private $leer;
/**
* #ORM\ManyToOne(targetEntity="usuario", inversedBy="libros")
*/
private $usuario;
/**
* #ORM\ManyToOne(targetEntity="libro", inversedBy="usuarios")
*/
private $libro;
public function __construct(Usuario $usuario, Libro $libro)
{
$this->usuario = $usuario;
$this->libro = $libro;
}
...
/**
* Get usuario
*
* #return \JavierGlez\Osprey\FrontendBundle\Entity\usuario
*/
public function getUsuario()
{
return $this->usuario;
}
/**
* Get libro
*
* #return \JavierGlez\Osprey\FrontendBundle\Entity\libro
*/
public function getLibro()
{
return $this->libro;
}
}
I can serch all the content with this SQL:
$query = $this->getEntityManager()
->createQuery(
"SELECT l, ul FROM JGOspreyFrontendBundle:Libro l
LEFT JOIN l.usuarios ul
LEFT JOIN ul.usuario u
JOIN l.colecciones c
WHERE c.id = :idColeccion AND (u.id = :idUsuario OR u.id IS NULL)")
->setParameters(array('idColeccion'=>$idColeccion, 'idUsuario'=>$idUsuario));
When I try to debug the variable, then the program gets blocked.
Anyone can help me???
Cheers

How can translatable in many-to-many relationship in Doctrine2? Symfony2

I've used Translatable with a personal translation; I've implemented PysTranslationand I've used ORM query hint in PysRepository. All of this works fine, the problem has been when I've translated the entity Genero. This entity has a many-to-many relationship with Pys entity and the above method doesn't work. How I can translate the $genNombre attribute of Generoentity?
/**
* Pys
*
* #ORM\Table(name="pys")
* #ORM\Entity(repositoryClass="Filmboot\PYSBundle\Entity\PysRepository")
* #Gedmo\TranslationEntity(class="Filmboot\PYSBundle\Entity\PysTranslation")
*/
class Pys
{
/**
* #var integer
*
* #ORM\Column(name="PYS_ID", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $pysId;
/**
* #var string
*
* #ORM\Column(name="PYS_STR", type="string", length=255, nullable=false)
* #Gedmo\Translatable
*/
private $pysStr;
/**
* #var string
*
* #ORM\Column(name="PYS_TITULO", type="string", length=255, nullable=true)
* #Gedmo\Translatable
*/
private $pysTitulo;
/**
* #var integer
*
* #ORM\Column(name="PYS_DURACION", type="integer", nullable=true)
*/
private $pysDuracion;
/**
* #var integer
*
* #ORM\Column(name="PYS_ANYO", type="integer", nullable=true)
*/
private $pysAnyo;
/**
* #var string
*
* #ORM\Column(name="PYS_PAIS", type="string", length=255, nullable=true)
* #Gedmo\Translatable
*/
private $pysPais;
/**
* #var string
*
* #ORM\Column(name="PYS_SINOPSIS", type="string", length=3000, nullable=true)
* #Gedmo\Translatable
*/
private $pysSinopsis;
/**
* #var string
*
* #ORM\Column(name="PYS_GUIONISTA", type="string", length=255, nullable=true)
*/
private $pysGuionista;
/**
* #ORM\ManyToOne(targetEntity="Filmboot\DirectorBundle\Entity\Director", cascade={"remove"})
* #ORM\JoinColumn(name="DIR_ID", referencedColumnName="DIR_ID", onDelete="CASCADE")
*/
private $director;
/**
* #var string
*
* #ORM\Column(name="PYS_IMAGEN", type="string", length=255, nullable=true)
*/
private $pysImagen;
/**
* #var string
*
* #ORM\Column(name="PYS_IMAGEN_GRANDE", type="string", length=255, nullable=true)
*/
private $pysImagenGrande;
/**
* #ORM\ManyToMany(targetEntity="\Filmboot\ActorBundle\Entity\Actor", mappedBy="peliculas", cascade={"remove"})
*/
private $actores;
/**
* #ORM\ManyToMany(targetEntity="\Filmboot\PYSBundle\Entity\Genero", mappedBy="peliculas", cascade={"remove"})
*/
private $generos;
/**
* #ORM\OneToMany(targetEntity="\Filmboot\PYSBundle\Entity\Premio", mappedBy="pys", cascade={"remove"})
* #ORM\JoinColumn(name="PRE_ID", referencedColumnName="PRE_ID", onDelete="CASCADE")
*/
private $premios;
/**
* #ORM\OneToMany(targetEntity="\Filmboot\UsuarioBundle\Entity\Voto", mappedBy="pys", cascade={"remove"})
* #ORM\JoinColumn(name="PYS_ID", referencedColumnName="PYS_ID", onDelete="CASCADE")
*/
private $votaciones;
/**
* #ORM\OneToMany(targetEntity="PysTranslation", mappedBy="object", cascade={"persist", "remove"})
*/
private $translations;
public function __construct()
{
$this->actores = new ArrayCollection();
$this->generos = new ArrayCollection();
$this->votaciones = new ArrayCollection();
$this->translations = new ArrayCollection();
}
public function getTranslations()
{
return $this->translations;
}
public function addTranslation(PysTranslation $t)
{
if (!$this->translations->contains($t)) {
$this->translations[] = $t;
$t->setObject($this);
}
}
This is Genero
<?php
namespace Filmboot\PYSBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* Genero
*
* #ORM\Table(name="genero")
* #ORM\Entity
*/
class Genero
{
/**
* #var integer
*
* #ORM\Column(name="GEN_ID", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $genId;
/**
* #var string
*
* #ORM\Column(name="GEN_NOMBRE", type="string", length=255, nullable=true)
* #Gedmo\Translatable
*/
private $genNombre;
/**
* #ORM\ManyToMany(targetEntity="\Filmboot\PYSBundle\Entity\Pys", inversedBy="generos")
* #ORM\JoinTable(name="P_GENERO",
* joinColumns={#ORM\JoinColumn(name="GEN_ID", referencedColumnName="GEN_ID")},
* inverseJoinColumns={#ORM\JoinColumn(name="PYS_ID", referencedColumnName="PYS_ID")}
* )
*/
private $peliculas;
This is PysTranslation
/**
* #ORM\Entity
* #ORM\Table(name="pys_translation", uniqueConstraints={#ORM\UniqueConstraint(name="lookup_unique_idx", columns={"locale", "object_id", "field"})})
*/
class PysTranslation extends AbstractPersonalTranslation
{
/**
* Convinient constructor
*
* #param string $locale
* #param string $field
* #param string $value
*/
public function __construct($locale, $field, $value)
{
$this->setLocale($locale);
$this->setField($field);
$this->setContent($value);
}
/**
* #ORM\ManyToOne(targetEntity="Pys", inversedBy="translations")
* #ORM\JoinColumn(name="object_id", referencedColumnName="PYS_ID", onDelete="CASCADE")
*/
protected $object;
}
This is PysRepository
class PysRepository extends EntityRepository
{
public function findPeliculas()
{
$em = $this->getEntityManager();
$consulta = $em->createQuery('
SELECT p, a, d, g, pr, v
FROM PYSBundle:Pys p
JOIN p.actores a JOIN p.director d JOIN p.generos g JOIN p.premios pr JOIN p.votaciones v
ORDER BY p.pysTitulo ASC
');
return $consulta->setHint(\Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER, 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker')->getResult();
}
/**
*
* #param string $pysStr El slug de la pelĂ­cula
*/
public function findPys($pysStr)
{
$em = $this->getEntityManager();
$consulta = $em->createQuery('
SELECT p, a, d, g, pr, v
FROM PYSBundle:Pys p
JOIN p.actores a JOIN p.director d JOIN p.generos g JOIN p.premios pr JOIN p.votaciones v
WHERE p.pysStr = :pysStr
');
$consulta->setParameter('pysStr', $pysStr);
return $consulta->setHint(\Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER, 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker')->getSingleResult();
}
}
I've solved the problem by adding this line in Genero entity annotations:
/**
* Genero
*
* #ORM\Table(name="genero")
* #ORM\Entity
* #Gedmo\TranslationEntity(class="Filmboot\PYSBundle\Entity\GeneroTranslation")
*/
class Genero

Resources