我在Symfony3项目中使用Doctrine。我正在使用实体管理器从数据库中获取数据,但我有一个意外的错误,似乎是由学说产生的。
在渲染模板期间抛出异常(“执行'SELECT t0.id AS id_1时发生异常,t0.date AS date_2,t0.comment AS comment_3,t0.viewed AS seen_4,t0.error_count AS error_count_5,t0.of_id AS of_id_6,t0.checkpoint_id AS checkpoint_id_7,t8.id AS id_9,t8.name AS name_10,t8.description AS description_11,t8.deleted_at AS deleted_at_12,t8.factory_id AS factory_id_13,t0.operateur_id AS operateur_id_15 ,t0.factory_id AS factory_id_16 FROM app_check_set t0 LEFT JOIN app_checkpoint t8 ON t0.checkpoint_id = t14.id AND((t14.deleted_at IS NULL))WHERE t0.factory_id =?ORDER BY t0.date DESC LIMIT 5'with params [3 ]:
SQLSTATE [42S22]:未找到列:1054'on clause'中的未知列't14.id'“)。
由于我不是自己创建查询,我想知道这个错误来自哪里?它与我的实体配置有关吗?
问题在于我想获取我的实体Checkset
:
public function notificationsAction(Request $request){
$user = $this->getUser();
$em = $this->getDoctrine()->getManager();
return $this->render('AppBundle:Home:notifications.html.twig', array(
'notifications' => $em->getRepository('AppBundle:CheckSet')->findBy(array('factory' => $user->getFactory()->getId()), array('date' => 'desc'), 5),
'count' => count($em->getRepository('AppBundle:CheckSet')->findBy(array('factory' => $user->getFactory()->getId(), 'viewed' => false)))
));
}
我的实体是这样的:
CheckSet:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use UserBundle\Entity\User;
use Doctrine\Common\Collections\ArrayCollection;
/**
* CheckSet
*
* @ORM\Table(name="app_check_set")
* @ORM\Entity(repositoryClass="AppBundle\Repository\CheckSetRepository")
*/
class CheckSet
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var \DateTime
*
* @ORM\Column(name="date", type="datetime")
*/
private $date;
/**
* @var string
* @ORM\Column(name="comment", type="text", nullable=true)
*/
private $comment;
/**
* @ORM\OneToMany(targetEntity="AppBundle\Entity\CheckElementResult", mappedBy="checkSet", cascade={"persist"})
*/
private $checkElementResult;
/**
* @ORM\OneToMany(targetEntity="AppBundle\Entity\CheckElementResultObservation", mappedBy="checkSet", cascade={"persist"})
*/
private $observations;
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Of", inversedBy="checkSet")
* @ORM\JoinColumn(name="of_id", referencedColumnName="id")
*/
private $of;
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\CheckPoint", inversedBy="checkSet", fetch="EAGER")
* @ORM\JoinColumn(name="checkpoint_id", referencedColumnName="id")
*/
private $checkPoint;
/**
* @ORM\ManyToOne(targetEntity="UserBundle\Entity\User", inversedBy="checkSet")
* @ORM\JoinColumn(name="operateur_id", referencedColumnName="id")
*/
private $operateur;
/**
* @ORM\Column(type="boolean", nullable=false, options={"default" : false})
*/
protected $viewed = FALSE;
/**
* @ORM\Column(type="integer", nullable=false)
*/
protected $errorCount;
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Factory", inversedBy="checkSet")
* @ORM\JoinColumn(name="factory_id", referencedColumnName="id")
*/
private $factory;
public function __construct($gamme = null, $of = null, $user = null){
$this->checkElementResult = new ArrayCollection();
$this->observations = new ArrayCollection();
$this->date = new \DateTime();
$this->errorCount = 0;
if ($gamme != null){
$this->checkPoint = $gamme;
}
if ($of != null){
$this->of = $of;
}
if ($user != null){
$this->operateur = $user;
$this->factory = $user->getFactory();
}
}
public function getId(){
return $this->id;
}
public function setDate($date){
$this->date = $date;
return $this;
}
public function getDate(){
return $this->date;
}
public function setErrorCount($errorCount){
$this->errorCount = $errorCount;
return $this;
}
public function getErrorCount(){
return $this->errorCount;
}
public function setComment($comment){
$this->comment = $comment;
return $this;
}
public function getComment(){
return $this->comment;
}
public function setOperateur(User $operateur){
$this->operateur = $operateur;
return $this;
}
public function getOperateur(){
return $this->operateur;
}
public function setOf(Of $of){
$this->of = $of;
return $this;
}
public function getOf(){
return $this->of;
}
public function setFactory(Factory $factory){
$this->factory = $factory;
return $this;
}
public function getFactory(){
return $this->factory;
}
public function setCheckPoint(Checkpoint $checkPoint){
$this->checkPoint = $checkPoint;
return $this;
}
public function getCheckPoint(){
return $this->checkPoint;
}
/*------------------------------------------------------------------------CheckElementResult*/
public function addCheckElementResult(CheckElementResult $cke){
$this->checkElementResult[] = $cke;
$cke->setCheckSet($this);
return $this;
}
public function removeCheckElementResult(CheckElementResult $cke){
$this->checkElementResult->removeElement($cke);
}
public function getcheckElementResult(){
return $this->checkElementResult;
}
/*------------------------------------------------------------------------observations*/
public function addObservations(CheckElementResultObservation $cke){
$this->observations[] = $cke;
$cke->setCheckSet($this);
return $this;
}
public function removeObservations(CheckElementResultObservation $cke){
$this->observations->removeElement($cke);
}
public function getObservations(){
return $this->observations;
}
/*-------------------------------------------------------VIEWED*/
public function setViewed($viewed){
$this->viewed = $viewed;
return $this;
}
public function getViewed(){
return $this->viewed;
}
public function isViewed(){
return $this->viewed;
}
public function countErrors(){
$err = 0;
foreach ($this->checkElementResult as $key => $ckeR) {
foreach ($ckeR->getCheckElement()->getAlert() as $key => $alert) {
if( $alert->getOperator() == "==" && $ckeR->getValue() == $alert->getValue()){
$err++;
}elseif ( $alert->getOperator() == "!=" && $ckeR->getValue() != $alert->getValue()) {
$err++;
}elseif ( $alert->getOperator() == "<" && $ckeR->getValue() < $alert->getValue()) {
$err++;
}elseif ( $alert->getOperator() == ">" && $ckeR->getValue() > $alert->getValue()) {
$err++;
}elseif ( $alert->getOperator() == "<=" && $ckeR->getValue() <= $alert->getValue()) {
$err++;
}elseif ( $alert->getOperator() == ">=" && $ckeR->getValue() >= $alert->getValue()) {
$err++;
}
}
}
return $err;
}
public function __toString(){
return $this->of->getName().' '.$this->checkPoint->getName();
}
}
检查点:
<?php
namespace AppBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* Checkpoint
*
* @ORM\Table(name="app_checkpoint")
* @ORM\Entity(repositoryClass="AppBundle\Repository\CheckpointRepository")
* @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
*/
class Checkpoint
{
/**
* @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="description", type="string", length=255, nullable=true)
*/
private $description;
/**
* @ORM\OneToMany(targetEntity="AppBundle\Entity\CheckElement", mappedBy="checkpoint",cascade={"persist"}, orphanRemoval=true)
* @ORM\OrderBy({"position" = "ASC"})
*/
private $checkElements;
/**
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Operation", mappedBy="checkpoint",cascade={"persist"})
*/
private $operation;
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Factory", inversedBy="checkpoints")
* @ORM\JoinColumn(name="factory_id", referencedColumnName="id")
*/
private $factory;
/**
* @ORM\OneToMany(targetEntity="AppBundle\Entity\CheckSet", mappedBy="checkPoint")
*/
private $checkSet;
/**
* @ORM\OneToMany(targetEntity="AppBundle\Entity\CheckListOf", mappedBy="checkPoint")
*/
private $checkListOf;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $deletedAt;
public function __construct(){
$this->checkElements = new ArrayCollection();
}
public function getId(){
return $this->id;
}
public function setName($name){
$this->name = $name;
return $this;
}
public function getName(){
return $this->name;
}
public function setDescription($description){
$this->description = $description;
return $this;
}
public function getDescription(){
return $this->description;
}
public function getFactory(){
return $this->factory;
}
public function setFactory($factory){
$this->factory = $factory;
}
/*------------------------------------------------------------------------Checkelements*/
public function addCheckElement(CheckElement $cke){
$this->checkElements[] = $cke;
$cke->setCheckpoint($this);
return $this;
}
public function removeCheckElement(CheckElement $cke){
$this->checkElements->removeElement($cke);
}
public function getCheckElements(){
return $this->checkElements;
}
public function __toString(){
return $this->name;
}
}
问题可能是因为软删除但我不确定......我正在调用的控制器(notificationsAction
)嵌入我的标题中。
在此页面(通知区域)中,我想显示可能已被删除的对象。我想要显示的checkpoint
(与Checkset对象相关的那个)已被删除时发生的问题
<!-- NOTIFICATIONS -->
{{ render(controller('AppBundle:Home:notifications', {'request': app.request})) }}
答案 0 :(得分:1)
您的问题实际上与here相同。
您的班级名称是检查点,我想该文件名为 checkpoint.php (请注意,如果您在Windows上开发,则文件名不区分大小写)。所有都是小写。
在你的CheckSet类中有
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\CheckPoint", inversedBy="checkSet", fetch="EAGER")
* @ORM\JoinColumn(name="checkpoint_id", referencedColumnName="id")
*/
private $checkPoint;
targetEntity 是“AppBundle \ Entity \ CheckPoint”,资本 P 。
问题在于,因此,doctrine为新表创建了一个新别名(php比较区分大小写github link)。
要解决此问题,请使用大写 P 将您的班级名称和文件更改为 CheckPoint :
class CheckPoint
{