I'm trying to get results from my table using limit and offsett from my table, and this table has a relations with another two tables.. one of them is MayToOne and the other is OneToOne
If I don't use setFirstResult and setMaxResults the results are the expected because return the information of my table and the information of the other tables related but using setFirst.. and setMax.. only return the information of the table and not the information of the tables related.
$query = $this->repository->createQueryBuilder('p')
->where('LOWER(p.name) LIKE LOWER(:term)')
->orWhere('LOWER(p.summary) LIKE LOWER(:term)')
->orwhere('LOWER(p.description) LIKE LOWER(:term)')
->setParameter('term', '%'.$parameters['term'].'%')
->setFirstResult($offset)
->setMaxResults($limit)
->orderBy('p.id','DESC')
->getQuery();
$attractions = $query->getResult();
And I'm trying with paginator using this query:
$query = $this->repository->createQueryBuilder('p')
->where('LOWER(p.name) LIKE LOWER(:term)')
->orWhere('LOWER(p.summary) LIKE LOWER(:term)')
->orwhere('LOWER(p.description) LIKE LOWER(:term)')
->setParameter('term', '%'.$parameters['term'].'%')
->setFirstResult($offset)
->setMaxResults($limit)
->orderBy('p.id','DESC');
$attractions = new Paginator($query, $fetchJoinCollection = true);
But is not working because appear this error:
[Semantical Error] The annotation "@Enum" in property Doctrine\ORM\Mapping\GeneratedValue::$strategy was never imported. Did you maybe forget to add a "use" statement for this annotation?
Entity
<?php
namespace Acme\MyBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Acme\MyBundle\Model\AttractionInterface;
use Gedmo\Mapping\Annotation as Gedmo;
use JMS\Serializer\Annotation\ExclusionPolicy;
use JMS\Serializer\Annotation\Exclude;
use JMS\Serializer\Annotation\Expose;
use JMS\Serializer;
/**
* Attraction
*
* @ORM\Table(name="attractions")
* @ORM\Entity
*
* @ExclusionPolicy("all")
*/
class Attraction implements AttractionInterface
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @Expose
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=150, nullable=false)
* @Expose
*/
private $name;
/**
* @var string
*
* @ORM\Column(name="latitude", type="string", length=30, nullable=false)
* @Expose
*/
private $latitude;
/**
* @var string
*
* @ORM\Column(name="longitude", type="string", length=30, nullable=false)
* @Expose
*/
private $longitude;
/**
* @var string
*
* @ORM\Column(name="summary", type="text", nullable=false)
* @Expose
*/
private $summary;
/**
* @var string
*
* @ORM\Column(name="description", type="text", nullable=true)
* @Expose
*/
private $description;
/**
* @var integer
*
* @ORM\Column(name="available_places", type="smallint")
* @Expose
*/
private $availablePlaces;
/**
* @var float
*
* @ORM\Column(name="original_price", type="float", nullable=false)
* @Expose
*/
private $originalPrice;
/**
* @var float
*
* @ORM\Column(name="new_price", type="float", nullable=false)
* @Expose
*/
private $newPrice;
/**
* @var \DateTime
*
* @ORM\Column(name="starting_point", type="datetime", nullable=false)
* @Expose
*/
private $startingPoint;
/**
* @var string
*
* @ORM\Column(name="picture", type="string", length=50, nullable=false)
* @Expose
*/
private $picture;
/**
* @var integer
*
* @ORM\ManyToOne(targetEntity="Vendor")
* @ORM\JoinColumn(name="vendor", referencedColumnName="id")
* @Expose
*/
private $vendor;
/**
* @var integer
*
* @ORM\OneToOne(targetEntity="Category")
* @ORM\JoinColumn(name="category", referencedColumnName="id")
* @Expose
*/
private $category;
/**
* @var \DateTime
*
* @ORM\Column(name="created_at", type="datetime", options={"default" = "CURRENT_TIMESTAMP"}, nullable=true)
* @Gedmo\Timestampable(on="create")
* @Expose
*/
private $createdAt;
/**
* @var \DateTime
*
* @ORM\Column(name="updated_at", type="datetime", options={"default" = "CURRENT_TIMESTAMP"}, nullable=true)
* @Expose
*/
private $updatedAt;
public function __toString()
{
return $this->name;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
* @return Attraction
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set latitude
*
* @param string $latitude
* @return Attraction
*/
public function setLatitude($latitude)
{
$this->latitude = $latitude;
return $this;
}
/**
* Get latitude
*
* @return string
*/
public function getLatitude()
{
return $this->latitude;
}
/**
* Set longitude
*
* @param string $longitude
* @return Attraction
*/
public function setLongitude($longitude)
{
$this->longitude = $longitude;
return $this;
}
/**
* Get longitude
*
* @return string
*/
public function getLongitude()
{
return $this->longitude;
}
/**
* Set summary
*
* @param string $summary
* @return Attraction
*/
public function setSummary($summary)
{
$this->summary = $summary;
return $this;
}
/**
* Get summary
*
* @return string
*/
public function getSummary()
{
return $this->summary;
}
/**
* Set description
*
* @param string $description
* @return Attraction
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set availablePlaces
*
* @param integer $availablePlaces
* @return Attraction
*/
public function setAvailablePlaces($availablePlaces)
{
$this->availablePlaces = $availablePlaces;
return $this;
}
/**
* Get availablePlaces
*
* @return integer
*/
public function getAvailablePlaces()
{
return $this->availablePlaces;
}
/**
* Set originalPrice
*
* @param float $originalPrice
* @return Attraction
*/
public function setOriginalPrice($originalPrice)
{
$this->originalPrice = $originalPrice;
return $this;
}
/**
* Get originalPrice
*
* @return float
*/
public function getOriginalPrice()
{
return $this->originalPrice;
}
/**
* Set newPrice
*
* @param float $newPrice
* @return Attraction
*/
public function setNewPrice($newPrice)
{
$this->newPrice = $newPrice;
return $this;
}
/**
* Get newPrice
*
* @return float
*/
public function getNewPrice()
{
return $this->newPrice;
}
/**
* Set startingPoint
*
* @param \DateTime $startingPoint
* @return Attraction
*/
public function setStartingPoint($startingPoint)
{
$this->startingPoint = \DateTime::createFromFormat('Y-m-d H:i:s', $startingPoint);
return $this;
}
/**
* Get startingPoint
*
* @return \DateTime
*/
public function getStartingPoint()
{
return $this->startingPoint;
}
/**
* Set picture
*
* @param string $picture
* @return Attraction
*/
public function setPicture($picture)
{
$this->picture = $picture;
return $this;
}
/**
* Get picture
*
* @return string
*/
public function getPicture()
{
return $this->picture;
}
/**
* Set vendor
*
* @param integer $vendor
* @return Attraction
*/
public function setVendor($vendor)
{
$this->vendor = $vendor;
return $this;
}
/**
* Get vendor
*
* @return integer
*/
public function getVendor()
{
return $this->vendor;
}
/**
* Set category
*
* @param integer $category
* @return Attraction
*/
public function setCategory($category)
{
$this->category = $category;
return $this;
}
/**
* Get categoryId
*
* @return integer
*/
public function getCategory()
{
return $this->category;
}
/**
* Set createdAt
*
* @param \DateTime $createdAt
* @return Attraction
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* Get createdAt
*
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set updatedAt
*
* @param \DateTime $updatedAt
* @return Attraction
*/
public function setUpdatedAt($updatedAt)
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* Get updatedAt
*
* @return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
}