我正在尝试在两个表之间创建多对一的单向关系。 dateTime
和availibilityList
是两个实体,一个列表可能有多个日期和时间。
我在实体dateTime中同样添加了注释,但它向我显示了这个错误:
{ 代码:500 消息:" [语义错误]第0行,第84行附近' d WHERE d.offerAvailibilityId':错误:类StreetBumb \ ApiBundle \ Entity \ availibilityList没有名为dateTime"的关联 }
我使用以下方法从终端更新了我的架构:
sudo php app/console doctrine:schema:update --force
它说:您的数据库已与当前实体元数据同步。
dateTime实体:
<?php
namespace StreetBumb\ApiBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* dateTime
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="StreetBumb\ApiBundle\Entity\dateTimeRepository")
*/
class dateTime
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var \DateTime
*
* @ORM\Column(name="startDate", type="date")
*/
private $startDate;
/**
* @var \DateTime
*
* @ORM\Column(name="endDate", type="date")
*/
private $endDate;
/**
* @var \DateTime
*
* @ORM\Column(name="startTime", type="time")
*/
private $startTime;
/**
* @var \DateTime
*
* @ORM\Column(name="endTime", type="time")
*/
private $endTime;
/**
* @var string
*
* @ORM\Column(name="type", type="string", length=55)
*/
private $type;
/**
* @var DateTime $offerAvailibilityId
*
* @ORM\ManyToOne(targetEntity="AvailibilityList")
* @ORM\JoinColumn(name="offerAvailibilityId", referencedColumnName="id")
*/
private $offerAvailibilityId;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set startDate
*
* @param \DateTime $startDate
* @return dateTime
*/
public function setStartDate($startDate)
{
$this->startDate = $startDate;
return $this;
}
/**
* Get startDate
*
* @return \DateTime
*/
public function getStartDate()
{
return $this->startDate;
}
/**
* Set endDate
*
* @param \DateTime $endDate
* @return dateTime
*/
public function setEndDate($endDate)
{
$this->endDate = $endDate;
return $this;
}
/**
* Get endDate
*
* @return \DateTime
*/
public function getEndDate()
{
return $this->endDate;
}
/**
* Set startTime
*
* @param \DateTime $startTime
* @return dateTime
*/
public function setStartTime($startTime)
{
$this->startTime = $startTime;
return $this;
}
/**
* Get startTime
*
* @return \DateTime
*/
public function getStartTime()
{
return $this->startTime;
}
/**
* Set endTime
*
* @param \DateTime $endTime
* @return dateTime
*/
public function setEndTime($endTime)
{
$this->endTime = $endTime;
return $this;
}
/**
* Get endTime
*
* @return \DateTime
*/
public function getEndTime()
{
return $this->endTime;
}
/**
* Set type
*
* @param string $type
* @return dateTime
*/
public function setType($type)
{
$this->type = $type;
return $this;
}
/**
* Get type
*
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* Set offerAvailibilityId
*
* @param integer $offerAvailibilityId
* @return dateTime
*/
public function setOfferAvailibilityId($offerAvailibilityId)
{
$this->offerAvailibilityId = $offerAvailibilityId;
return $this;
}
/**
* Get offerAvailibilityId
*
* @return integer
*/
public function getOfferAvailibilityId()
{
return $this->offerAvailibilityId;
}
}
我正在控制器中调用存储库中的函数。
public function findOpeningDetailById($id)
{
$qb = $this->getEntityManager()->createQueryBuilder()
->select('list')
->from('StreetBumbApiBundle:availibilityList', 'list')
->innerJoin('list.dateTime', 'd')
->where('d.offerAvailibilityId = :id')->setParameter('id', $id) //This line is showing error
->getQuery()->getResult();
return $qb;
}
我的联接查询中存在任何问题或我所建立的关系(多对一)是否有误? 请指导.. 谢谢