我在我的symfony3项目中使用理论。我正在使用实体管理器从数据库获取数据,但我有一个意外错误,似乎是由条令生成的。
在呈现模板的过程中引发了异常(“在执行'select t0.id as id\u 1,t0.date as date\u 2,t0.comment as comment\u 3,t0.view as view\u 4,t0.error\u count as error\u count\u 5,t0.of\u id as of \u id of \u 6,t0.checkpoint\u id as checkpoint\u 7,t8.id as id\u 9,t8.name as name\u 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)),其中t0.factory_id=?order by t0.date desc limit 5'带参数[3]:
sqlstate[42s22]:找不到列:“on子句”中的1054未知列“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)))
));
}
我的实体是这样的:
检查集:
<?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
我要显示的(与检查集对象相关的)已被删除
<!-- NOTIFICATIONS -->
{{ render(controller('AppBundle:Home:notifications', {'request': app.request})) }}
1条答案
按热度按时间kqqjbcuj1#
你的问题其实和这里一样。
您的类名是checkpoint,我猜文件名是checkpoint.php(请注意,如果您是在windows上开发的,则文件名不区分大小写)。都是小写的。
在checkset类中
目标实体为“appbundle\entity\checkpoint”,大写p。
问题是,正因为如此,我们为一个新表创建了一个新的别名(php比较是区分大小写的github链接)。
要解决此问题,请将类名和文件更改为checkpoint,大写p: