Foros del Web » Programando para Internet » PHP » Symfony »

Duda con una consulta DQL

Estas en el tema de Duda con una consulta DQL en el foro de Symfony en Foros del Web. Hola de nuevo, tengo un problema con una consulta DQL. Les explico lo que quiero hacer, Tengo una entidad llamada DatoItem, otra llamada Item. La ...
  #1 (permalink)  
Antiguo 28/07/2013, 22:21
 
Fecha de Ingreso: junio-2013
Mensajes: 14
Antigüedad: 10 años, 10 meses
Puntos: 0
Duda con una consulta DQL

Hola de nuevo, tengo un problema con una consulta DQL. Les explico lo que quiero hacer,
Tengo una entidad llamada DatoItem, otra llamada Item.
La entidad item, representa justamente eso, tiene una categoria y descripcion, y demas detalles, el dato_item es el dato que se relaciona con el item(contenido del item) .

Ahora bien, la idea mia por ejemplo, es que yo inicialmente selecciono la opcion completar datos
Esto me genera un listado con todos los items presentes en el sistema y un textbox date o textarea segun sea el caso.(pueden ser de esos 3 tipos) al lado de cada item.
Ese input que va en el campo de texto es mi dato item.
Cada datoItem tiene una relacion OneToOne con la entidad Item.
Lo que quiero hacer es que cuando se genere el listado que mencione, me figuren solamente aquellos items los cuales no tienen relacionado un dato item para ese usuario, digamos aquellos items que no se completaron todavia
O sea hacer una diferencia entre Items y datositems y lo que queda serian los items que no tienen datos items asociados.
No se si se entiende la idea. Publico abajo la consulta que quise hacer y las 2 entidades, a ver si a alguien se le ocurre algo.


<?php

namespace P2012\SistemaCvBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* DatoItem
*
* @ORM\Table(name="dato_item")
* @ORM\Entity
*/
class DatoItem
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;

/**
* @ORM\ManyToOne(targetEntity="Usuario", inversedBy="datositem")
*/
private $usuarioId;

/**
* @ORM\OneToOne(targetEntity="Item")
*/
private $itemId;

/**
* @var string
*
* @ORM\Column(name="contenido", type="text", nullable=false)
*/
private $contenido;

/**
* @var \DateTime
*
* @ORM\Column(name="fecha_inicio", type="date", nullable=true)
*/
private $fechaInicio;

/**
* @var \DateTime
*
* @ORM\Column(name="fecha_fin", type="date", nullable=true)
*/
private $fechaFin;

/**
* @var string
*
* @ORM\Column(name="entidad_otorgante", type="string", length=255, nullable=true)
*/
private $entidadOtorgante;

/**
* @var string
*
* @ORM\Column(name="entidad_destinataria", type="string", length=255, nullable=true)
*/
private $entidadDestinataria;

/**
* @var string
*
* @ORM\Column(name="caracter", type="string", length=255, nullable=true)
*/
private $caracter;



/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}

/**
* Set usuarioId
*
* @param integer $usuarioId
* @return DatoItem
*/
public function setUsuarioId($usuarioId)
{
$this->usuarioId = $usuarioId;

return $this;
}

/**
* Get usuarioId
*
* @return integer
*/
public function getUsuarioId()
{
return $this->usuarioId;
}

/**
* Set itemId
*
* @param integer $itemId
* @return DatoItem
*/
public function setItemId($itemId)
{
$this->itemId = $itemId;

return $this;
}

/**
* Get itemId
*
* @return integer
*/
public function getItemId()
{
return $this->itemId;
}

/**
* Set contenido
*
* @param string $contenido
* @return DatoItem
*/
public function setContenido($contenido)
{
$this->contenido = $contenido;

return $this;
}

/**
* Get contenido
*
* @return string
*/
public function getContenido()
{
return $this->contenido;
}
}
++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++
<?php

namespace P2012\SistemaCvBundle\Entity;
use Symfony\Bridge\Doctrine\Validator\Constraints\Uniq ueEntity;

use Doctrine\ORM\Mapping as ORM;

/**
* Item
*
* @ORM\Table(name="item")
* @ORM\Entity(repositoryClass="P2012\SistemaCvBundle \Entity\ItemRepository")
* @UniqueEntity("descripcion")
*
*/
class Item
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/

protected $id;

/**
* @ORM\ManyToOne(targetEntity="CategoriaItem", inversedBy="catItem")
*
*
*/
protected $categoria;

/**
* @ORM\OneToMany(targetEntity="Elemento", mappedBy="link")
*/
protected $elemento;

/**
* @var string
*
* @ORM\Column(name="descripcion", type="string", length=255, nullable=false,unique=true)
*/
protected $descripcion;




/**
* @var boolean
*
* @ORM\Column(name="buscable", type="boolean", nullable=false)
*/
protected $buscable;

/**
* @var boolean
*
* @ORM\Column(name="repetible", type="boolean", nullable=false)
*/
protected $repetible;

/**
* @ORM\ManyToOne(targetEntity="TipoItem",inversedBy= "items")
* @ORM\JoinColumn(name="tipoitem_id", referencedColumnName="id")
*
*/
protected $tipoItem;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}



/**
* Set descripcion
*
* @param string $descripcion
* @return Item
*/
public function setDescripcion($descripcion)
{
$this->descripcion = $descripcion;

return $this;
}

/**
* Get descripcion
*
* @return string
*/
public function getDescripcion()
{
return $this->descripcion;
}

/**
* Set tipoItemId
*
* @param integer $tipoItemId
* @return Item
*/
public function setTipoItemId($tipoItemId)
{
$this->tipoItemId = $tipoItemId;

return $this;
}

/**
* Get tipoItemId
*
* @return integer
*/
public function getTipoItemId()
{
return $this->tipoItemId;
}

/**
* Set buscable
*
* @param boolean $buscable
* @return Item
*/
public function setBuscable($buscable)
{
$this->buscable = $buscable;

return $this;
}

/**
* Get buscable
*
* @return boolean
*/
public function getBuscable()
{
return $this->buscable;
}

/**
* Set repetible
*
* @param boolean $repetible
* @return Item
*/
public function setRepetible($repetible)
{
$this->repetible = $repetible;

return $this;
}

/**
* Get repetible
*
* @return boolean
*/
public function getRepetible()
{
return $this->repetible;
}

/**
* Set categoria
*
* @param \P2012\SistemaCvBundle\Entity\CategoriaItem $categoria
* @return Item
*/
public function setCategoria(\P2012\SistemaCvBundle\Entity\Categor iaItem $categoria = null)
{
$this->categoria = $categoria;

return $this;
}

/**
* Get categoria
*
* @return \P2012\SistemaCvBundle\Entity\CategoriaItem
*/
public function getCategoria()
{
return $this->categoria;
}

/**
* Set tipoItem
*
* @param \P2012\SistemaCvBundle\Entity\TipoItem $tipoItem
* @return Item
*/
public function setTipoItem(\P2012\SistemaCvBundle\Entity\TipoItem $tipoItem = null)
{
$this->tipoItem = $tipoItem;

return $this;
}

/**
* Get tipoItem
*
* @return \P2012\SistemaCvBundle\Entity\TipoItem
*/
public function getTipoItem()
{
return $this->tipoItem;
}
}
++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++


CONSULTA DQL

public function getElementsTypeItems($id_pl)
{
/**
* Consulta que obtiene todos los elementos que son de tipo text,textarea o date unicamente pertenencientes a la plantilla con $id_pl

*/
$query = $this->getEntityManager()
->createQuery('SELECT e FROM P2012SistemaCvBundle:Elemento e JOIN e.link i JOIN i.tipoItem ti
WHERE ti.descripcion = :tipo
OR ti.descripcion = :tipo2 OR ti.descripcion = :tipo3
AND e.plantilla = :id_pl');
$query->setParameter(':tipo','Textarea');
$query->setParameter(':tipo2','Text');
$query->setParameter(':tipo3', 'Date');
$query->setParameter(':id_pl',$id_pl);

$elem = $query->getResult();
/* Aca obtiene aquellos items que sean tipo textarea text o date para la plantilla $idpl

$query2 = $this->getEntityManager()
->createQuery('SELECT i FROM P2012SistemaCvBundle:Item i WHERE i.id NOT IN(:param)');
$query2->setParameter(':param',$elem);
return $query2;

}
Esta consulta se que no anda, porque estoy comparando dato_item con item, pero la verdad no se como hacerlo usando DQL
Muchas gracias, espero que se entienda!
Saludos!

Etiquetas: Ninguno
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 10:22.