这段代码中的错误
我想用多连接创建查询,但不幸的是显示了这个错误
[这是我的SearchController控制器]
class SearchController extends Controller {
public function indexAction() {
$em = $this->get('doctrine.orm.entity_manager');
$users = $em
->createQueryBuilder('P')
->select('P.pname, Q.qname,P.gender,P.phone,P.yearsOfExperience,P.graduationYear,c.cname')
->add('from', 'serachBundle:Person P')
->Join('P.Qualification', 'Q')
->Join('Q.Category', 'c')
->where('P.qualificationId=Q.id')
->andwhere('Q.categoryId=c.id')
->getQuery();
$user = $users->getResult();
print_r($user);
//qualification
$Qlist = $this->getDoctrine()
->getRepository('serachBundle:qualification')
->findAll();
//category
$Catlist = $this->getDoctrine()
->getRepository('serachBundle:category')
->findAll();
return $this->render('serachBundle:Default:Search.html.twig', array('user' => $user, 'Qlist' => $Qlist, 'Catlist' => $Catlist));
}
这个我的人实体
<?php
namespace Search\serachBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Person
*
* @ORM\Table(name="person", indexes={@ORM\Index(name="companyId", columns={"companyId", "qualificationId"}), @ORM\Index(name="qualificationId", columns={"qualificationId"}), @ORM\Index(name="IDX_34DCD1762480E723", columns={"companyId"})})
* @ORM\Entity
*/
class Person
{
/**
* @var string
*
* @ORM\Column(name="pname", type="string", length=255, nullable=false)
*/
private $pname;
/**
* @var string
*
* @ORM\Column(name="address", type="string", length=255, nullable=false)
*/
private $address;
/**
* @var string
*
* @ORM\Column(name="phone", type="string", length=255, nullable=false)
*/
private $phone;
/**
* @var string
*
* @ORM\Column(name="gender", type="string", length=255, nullable=false)
*/
private $gender;
/**
* @var integer
*
* @ORM\Column(name="yearsOfExperience", type="integer", nullable=false)
*/
private $yearsofexperience;
/**
* @var integer
*
* @ORM\Column(name="graduationYear", type="integer", nullable=false)
*/
private $graduationyear;
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var \Search\serachBundle\Entity\Company
*
* @ORM\ManyToOne(targetEntity="Search\serachBundle\Entity\Company")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="companyId", referencedColumnName="id")
* })
*/
private $companyid;
/**
* @var \Search\serachBundle\Entity\Qualification
*
* @ORM\ManyToOne(targetEntity="Search\serachBundle\Entity\Qualification")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="qualificationId", referencedColumnName="id")
* })
*/
private $qualificationid;
/**
* Set pname
*
* @param string $pname
* @return Person
*/
public function setPname($pname)
{
$this->pname = $pname;
return $this;
}
/**
* Get pname
*
* @return string
*/
public function getPname()
{
return $this->pname;
}
/**
* Set address
*
* @param string $address
* @return Person
*/
public function setAddress($address)
{
$this->address = $address;
return $this;
}
/**
* Get address
*
* @return string
*/
public function getAddress()
{
return $this->address;
}
/**
* Set phone
*
* @param string $phone
* @return Person
*/
public function setPhone($phone)
{
$this->phone = $phone;
return $this;
}
/**
* Get phone
*
* @return string
*/
public function getPhone()
{
return $this->phone;
}
/**
* Set gender
*
* @param string $gender
* @return Person
*/
public function setGender($gender)
{
$this->gender = $gender;
return $this;
}
/**
* Get gender
*
* @return string
*/
public function getGender()
{
return $this->gender;
}
/**
* Set yearsofexperience
*
* @param integer $yearsofexperience
* @return Person
*/
public function setYearsofexperience($yearsofexperience)
{
$this->yearsofexperience = $yearsofexperience;
return $this;
}
/**
* Get yearsofexperience
*
* @return integer
*/
public function getYearsofexperience()
{
return $this->yearsofexperience;
}
/**
* Set graduationyear
*
* @param integer $graduationyear
* @return Person
*/
public function setGraduationyear($graduationyear)
{
$this->graduationyear = $graduationyear;
return $this;
}
/**
* Get graduationyear
*
* @return integer
*/
public function getGraduationyear()
{
return $this->graduationyear;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set companyid
*
* @param \Search\serachBundle\Entity\Company $companyid
* @return Person
*/
public function setCompanyid(\Search\serachBundle\Entity\Company $companyid = null)
{
$this->companyid = $companyid;
return $this;
}
/**
* Get companyid
*
* @return \Search\serachBundle\Entity\Company
*/
public function getCompanyid()
{
return $this->companyid;
}
/**
* Set qualificationid
*
* @param \Search\serachBundle\Entity\Qualification $qualificationid
* @return Person
*/
public function setQualificationid(\Search\serachBundle\Entity\Qualification $qualificationid = null)
{
$this->qualificationid = $qualificationid;
return $this;
}
/**
* Get qualificationid
*
* @return \Search\serachBundle\Entity\Qualification
*/
public function getQualificationid()
{
return $this->qualificationid;
}
}
(实体是具有身份的对象。他们的身份在您的域内具有概念意义。在CMS应用程序中,每篇文章都有唯一的ID。您可以通过该ID唯一地标识每篇文章。)
这是我的资格认证实体
<?php
namespace Search\serachBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Qualification
*
* @ORM\Table(name="qualification", indexes={@ORM\Index(name="categoryId", columns={"categoryId"})})
* @ORM\Entity
*/
class Qualification
{
/**
* @var string
*
* @ORM\Column(name="qname", type="string", length=255, nullable=false)
*/
private $qname;
/**
* @var string
*
* @ORM\Column(name="specialty", type="string", length=255, nullable=false)
*/
private $specialty;
/**
* @var string
*
* @ORM\Column(name="qualifDesc", type="string", length=255, nullable=false)
*/
private $qualifdesc;
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var \Search\serachBundle\Entity\Category
*
* @ORM\ManyToOne(targetEntity="Search\serachBundle\Entity\Category")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="categoryId", referencedColumnName="id")
* })
*/
private $categoryid;
/**
* Set qname
*
* @param string $qname
* @return Qualification
*/
public function setQname($qname)
{
$this->qname = $qname;
return $this;
}
/**
* Get qname
*
* @return string
*/
public function getQname()
{
return $this->qname;
}
/**
* Set specialty
*
* @param string $specialty
* @return Qualification
*/
public function setSpecialty($specialty)
{
$this->specialty = $specialty;
return $this;
}
/**
* Get specialty
*
* @return string
*/
public function getSpecialty()
{
return $this->specialty;
}
/**
* Set qualifdesc
*
* @param string $qualifdesc
* @return Qualification
*/
public function setQualifdesc($qualifdesc)
{
$this->qualifdesc = $qualifdesc;
return $this;
}
/**
* Get qualifdesc
*
* @return string
*/
public function getQualifdesc()
{
return $this->qualifdesc;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set categoryid
*
* @param \Search\serachBundle\Entity\Category $categoryid
* @return Qualification
*/
public function setCategoryid(\Search\serachBundle\Entity\Category $categoryid = null)
{
$this->categoryid = $categoryid;
return $this;
}
/**
* Get categoryid
*
* @return \Search\serachBundle\Entity\Category
*/
public function getCategoryid()
{
return $this->categoryid;
}
}
如果有人能解决这个问题,请提前致谢。这将是一个非常好的帮助
答案 0 :(得分:0)
您将关系命名为$ qualificationid,因此您应该使您的查询如下:
->Join('P.qualificationid', 'Q')
->Join('Q.categoryid', 'c')
请记住在存储库类中进行所有查询。并且请尝试将您的捆绑包从serach重命名为搜索:-D