我試圖從我的表中使用限制和偏移量從我的表中得到結果,並且此表與另外兩個表有關係..其中之一是MayToOne另一個是OneToOneSymfony2,學說限制和偏移量不能按預期工作
如果我不使用setFirstResult和setMaxResults結果是預期的,因爲返回我的表的信息和其他表的信息,但使用setFirst ..和setMax ..只返回表格的信息而不是相關表格的信息。
$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();
我正與分頁程序使用此查詢嘗試:
$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);
但沒有工作,因爲出現這樣的錯誤:
[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?
實體
<?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;
}
}
由於您的實體中有錯誤而發生此錯誤。您不必在必要時導入Enum註釋。請出示您的實體。 – tom 2014-09-28 00:29:15
當然,我添加了實體。 – SoldierCorp 2014-09-28 19:16:17
你可以在你的其他實體中搜索Enum嗎?如果你找到一個貼在這裏。謝謝 – tom 2014-09-29 07:20:25