I am trying to create a many to one unidirectional relationship between two tables. dateTime
and availibilityList
are two entities, one list may have multiple date and time.
I added the annotations likewise in the entity dateTime but it is showing me this error:
{ code: 500 message: "[Semantical Error] line 0, col 84 near 'd WHERE d.offerAvailibilityId': Error: Class StreetBumb\ApiBundle\Entity\availibilityList has no association named dateTime" }
I updated my schema from the terminal by using this:
sudo php app/console doctrine:schema:update --force
It says : your database is already in sync with the current entity metadata.
dateTime Entity:
<?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;
}
}
The function in repository i am calling in controller.
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;
}
Is there any problem in my join query or the relation i made(Many to one) is incorrect? Please guide.. Thank you