I am trying to build a log of some action performed on some site using Symfony2 and Doctrine. I have 2 tables Sites and Logs. The Logs table will contain a siteid which is a foreign key to the id column of sites table. The Logs table can have multiple logs for same site.
When I try to insert an entry in the log table I get siteid is null error.
Here is my code:
Sites Entity:
<?php
namespace A\SHB\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Sites
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="A\SHB\Entity\SitesRepository")
*/
class Sites
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var ArrayCollection $siteLog
*
* #ORM\OneToMany(targetEntity="Logs", mappedBy="log", cascade={"persist"})
* #ORM\OrderBy({"siteid" = "ASC"})
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="log_id", referencedColumnName="siteid")
* })
*/
private $siteLog;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Constructor
*/
public function __construct()
{
$this->siteLog = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add siteLog
*
* #param \A\SHB\Entity\SiteLog $siteLog
* #return Sites
*/
public function addSiteLog(\A\SHB\Entity\SiteLog $siteLog)
{
$this->siteLog[] = $siteLog;
return $this;
}
/**
* Remove siteLog
*
* #param \A\SHB\Entity\SiteLog $siteLog
*/
public function removeSiteLog(\A\SHB\Entity\SiteLog $siteLog)
{
$this->siteLog->removeElement($siteLog);
}
/**
* Get siteLog
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getSiteLog()
{
return $this->siteLog;
}
}
Logs Entity:
<?php
namespace A\SHB\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Logs
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="A\SHB\Entity\LogsRepository")
*/
class Logs
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var integer
*
* #ORM\Column(name="siteid", type="integer")
*/
private $siteid;
/**
* #var integer
*
* #ORM\Column(name="dateline", type="integer")
*/
private $dateline;
/**
* #var Log
*
* #ORM\ManyToOne(targetEntity="Sites")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="site_id", referencedColumnName="id")
* })
*/
private $log;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set siteid
*
* #param integer $siteid
* #return Logs
*/
public function setSiteid($siteid)
{
$this->siteid = $siteid;
return $this;
}
/**
* Get siteid
*
* #return integer
*/
public function getSiteid()
{
return $this->siteid;
}
/**
* Set dateline
*
* #param integer $dateline
* #return Logs
*/
public function setDateline($dateline)
{
$this->dateline = $dateline;
return $this;
}
/**
* Get dateline
*
* #return integer
*/
public function getDateline()
{
return $this->dateline;
}
/**
* Set log
*
* #param \A\SHB\Entity\Log $log
* #return Logs
*/
public function setLog(\A\SHB\Entity\Log $log = null)
{
$this->log = $log;
return $this;
}
/**
* Get log
*
* #return \A\SHB\Entity\Log
*/
public function getLog()
{
return $this->log;
}
}
Controller :
public function indexAction()
{
$sites = $this->getDoctrine()->getRepository('ASHB:Sites')->findAll();
foreach ($sites as $site)
{
$host = $site->getForum();
// Do something ....
$log = new Logs();
$log->setSiteid($site->getId());
$log->setDateline($temp['dateline']);
$em = $this->getDoctrine()->getManager();
$em->persist($log);
$em->flush();
}
return $this->render('ASHB:Default:index.html.twig', array('sites' => $output, 'counters' => $counters));
}
Now when I run this code, I get the following error:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'siteid' cannot be null"
If I var_dump $log, before $em->persist($log);, the siteid is there. I am not sure what is wrong and why the siteid is getting set to null.
Update 1:
I tried to make the following changes and still get the same error:
/**
* #var Log
*
* #ORM\ManyToOne(targetEntity="Sites", inversedBy="siteLog")
*/
private $log;
OneToMany doesn't need a JoinColumn. So it should look like, according to the documentation.
class Sites
{
/**
* #ORM\OneToMany(targetEntity="Logs", mappedBy="log")
*/
private $site_log;
}
class Logs
{
/**
* #ORM\ManyToOne(targetEntity="Sites", inversedBy="site_log")
* #ORM\JoinColumn(name="site_id", referencedColumnName="id")
*/
private $log;
}
orderBy and cascade were ignored for simplicity.
you have problem in your sturcture,
Remove this from Logs Entity
/**
* #var integer
*
* #ORM\Column(name="siteid", type="integer")
*/
private $siteid;
And then replace this part
/**
* #var Log
*
* #ORM\ManyToOne(targetEntity="Sites")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="site_id", referencedColumnName="id")
* })
*/
private $log;
with
/**
* #var Log
*
* #ORM\ManyToOne(targetEntity="Sites" inversedBy="logs")
*/
private $site;
And in your sites entity replace this with
/**
* #var ArrayCollection $siteLog
*
* #ORM\OneToMany(targetEntity="Logs", mappedBy="logs", cascade={"persist"})
* #ORM\OrderBy({"siteid" = "ASC"})
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="log_id", referencedColumnName="siteid")
* })
*/
private $logs;
with
/**
* #var ArrayCollection $siteLog
*
* #ORM\OneToMany(targetEntity="Logs", mappedBy="site", cascade={"persist"})
* #ORM\OrderBy({"siteid" = "ASC"})
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="log_id", referencedColumnName="id")
* })
*/
private $logs;
And then use proper setters and getters for these new feilds mean pass object to setter functions, for the class they are being mapped for(if you dont know this part write in comment i will do it as well)
Related
I have entity for saving place's working time:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* WorkingTime
*
* #ORM\Table(name="working_time")
* #ORM\Entity(repositoryClass="AppBundle\Repository\WorkingTimeRepository")
*/
class WorkingTime
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var int
*
* #ORM\Column(name="day", type="smallint")
*/
private $day;
/**
* #var \DateTime
*
* #ORM\Column(name="start", type="time")
*/
private $start;
/**
* #var \DateTime
*
* #ORM\Column(name="end", type="time")
*/
private $end;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set day
*
* #param integer $day
*
* #return WorkingTime
*/
public function setDay($day)
{
$this->day = $day;
return $this;
}
/**
* Get day
*
* #return integer
*/
public function getDay()
{
return $this->day;
}
/**
* Set start
*
* #param \DateTime $start
*
* #return WorkingTime
*/
public function setStart($start)
{
$this->start = $start;
return $this;
}
/**
* Get start
*
* #return \DateTime
*/
public function getStart()
{
return $this->start;
}
/**
* Set end
*
* #param \DateTime $end
*
* #return WorkingTime
*/
public function setEnd($end)
{
$this->end = $end;
return $this;
}
/**
* Get end
*
* #return \DateTime
*/
public function getEnd()
{
return $this->end;
}
}
But when I try to display retrieve it, time fields are converted to something like:
{
"id": 16,
"day": 2,
"start": "1970-01-01T07:00:00+0000",
"end": "1970-01-01T00:00:00+0000"
},
Is it possible, that it gets converted by FOSRestBundle? How can I get rid of it and get only HH:mm, instead of 1970-01-01T00:00:00+0000?
The FOSRestBundle serialises objects before render them.
To do this, you need to choose between the built-in Symfony serializer or the JMSSerializer.
As you don't manually use one of them for now, and because it provides a solution for this specific problem, I will give the solution for do it using the JMSSerializer.
To use it, you need only to follow the installation chapter of the documentation.
Then, in your entity, use the #Type annotation on the time properties :
use JMS\Serializer\Annotation as JMS;
// ...
/**
* #JMS\Type("DateTime<'H:i'>")
* #ORM\Column(name="start", type="time")
*/
private $start;
/**
* #JMS\Type("DateTime<'H:i'>")
* #ORM\Column(name="end", type="time")
*/
private $end;
Now, your properties will be rendered as 07:00 instead of 1970-01-01T07:00:00+0000.
I am currently facing one problem with mapping I hope some one would helpe me.
I have two table describe bellow..
unitid(primary_key, column_1)
For example data here
unitid(1,22)
unitid (2,33)
mappaths(primary key, forign_key (column_1), forign_key(column_1))
For example data here
mappaths (1,22,33)
mappaths (2,33,22)
unitid has some kind of units defines while this mappaths table define the specific paths based on the unitid
Now when I run the doctrain2 mapping It give me some kind these entities pluse these following mapping information
Entity class
<?php
namespace ApiMaps\ApiMapBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Mappaths
*
* #ORM\Table(name="mappaths", indexes={#ORM\Index(name="idx_45b7519fa3995845", columns={"ref_unitids1"}), #ORM\Index(name="idx_45b7519f3a9009ff", columns={"ref_unitids2"})})
* #ORM\Entity
*/
class Mappaths
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="SEQUENCE")
* #ORM\SequenceGenerator(sequenceName="mappaths_id_seq", allocationSize=1, initialValue=1)
*/
private $id;
/**
* #var integer
*
* #ORM\Column(name="normalvalue", type="smallint", nullable=true)
*/
private $normalvalue;
/**
*
* #var \Unitids
* #ORM\ManyToOne(targetEntity="Unitids",cascade={"all"},fetch="LAZY")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="ref_unitids2", referencedColumnName="databaseid")
* })
*/
private $refUnitids2;
/**
* #var \Unitids
* #ORM\ManyToOne(targetEntity="Unitids",cascade={"all"},fetch="LAZY")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="ref_unitids1", referencedColumnName="databaseid")
* })
*/
private $refUnitids1;
/**
* Set normalvalue
*
* #param integer $normalvalue
*
* #return Mappaths
*/
public function setNormalvalue($normalvalue)
{
$this->normalvalue = $normalvalue;
return $this;
}
/**
* Get normalvalue
*
* #return integer
*/
public function getNormalvalue()
{
return $this->normalvalue;
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set refUnitids1
*
* #param \ApiMaps\ApiMapBundle\Entity\Unitids $refUnitids1
*
* #return Mappaths
*/
public function setRefUnitids1(\ApiMaps\ApiMapBundle\Entity\Unitids $refUnitids1 = null)
{
$this->refUnitids1 = $refUnitids1;
return $this;
}
/**
* Get refUnitids1
*
* #return \ApiMaps\ApiMapBundle\Entity\Unitids
*/
public function getRefUnitids1()
{
return $this->refUnitids1;
}
/**
* Set refUnitids2
*
* #param \ApiMaps\ApiMapBundle\Entity\Unitids $refUnitids2
*
* #return Mappaths
*/
public function setRefUnitids2(\ApiMaps\ApiMapBundle\Entity\Unitids $refUnitids2 = null)
{
$this->refUnitids2 = $refUnitids2;
return $this;
}
/**
* Get refUnitids2
*
* #return \ApiMaps\ApiMapBundle\Entity\Unitids
*/
public function getRefUnitids2()
{
return $this->refUnitids2;
}
}
and mappaths.php
<?php
namespace ApiMaps\ApiMapBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Mappaths
*
* #ORM\Table(name="mappaths", indexes={#ORM\Index(name="idx_45b7519fa3995845", columns={"ref_unitids1"}), #ORM\Index(name="idx_45b7519f3a9009ff", columns={"ref_unitids2"})})
* #ORM\Entity
*/
class Mappaths
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="SEQUENCE")
* #ORM\SequenceGenerator(sequenceName="mappaths_id_seq", allocationSize=1, initialValue=1)
*/
private $id;
/**
* #var integer
*
* #ORM\Column(name="normalvalue", type="smallint", nullable=true)
*/
private $normalvalue;
/**
*
* #var \Unitids
* #ORM\ManyToOne(targetEntity="Unitids",cascade={"all"},fetch="LAZY")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="ref_unitids2", referencedColumnName="databaseid")
* })
*/
private $refUnitids2;
/**
* #var \Unitids
* #ORM\ManyToOne(targetEntity="Unitids",cascade={"all"},fetch="LAZY")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="ref_unitids1", referencedColumnName="databaseid")
* })
*/
private $refUnitids1;
/**
* Set normalvalue
*
* #param integer $normalvalue
*
* #return Mappaths
*/
public function setNormalvalue($normalvalue)
{
$this->normalvalue = $normalvalue;
return $this;
}
/**
* Get normalvalue
*
* #return integer
*/
public function getNormalvalue()
{
return $this->normalvalue;
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set refUnitids1
*
* #param \ApiMaps\ApiMapBundle\Entity\Unitids $refUnitids1
*
* #return Mappaths
*/
public function setRefUnitids1(\ApiMaps\ApiMapBundle\Entity\Unitids $refUnitids1 = null)
{
$this->refUnitids1 = $refUnitids1;
return $this;
}
/**
* Get refUnitids1
*
* #return \ApiMaps\ApiMapBundle\Entity\Unitids
*/
public function getRefUnitids1()
{
return $this->refUnitids1;
}
/**
* Set refUnitids2
*
* #param \ApiMaps\ApiMapBundle\Entity\Unitids $refUnitids2
*
* #return Mappaths
*/
public function setRefUnitids2(\ApiMaps\ApiMapBundle\Entity\Unitids $refUnitids2 = null)
{
$this->refUnitids2 = $refUnitids2;
return $this;
}
/**
* Get refUnitids2
*
* #return \ApiMaps\ApiMapBundle\Entity\Unitids
*/
public function getRefUnitids2()
{
return $this->refUnitids2;
}
}
now when I run the project it give me the following error
37. public static function missingPrimaryKeyValue($className, $idField)
38. {
39. return new self(sprintf("Missing value for primary key %s on %s", $idField, $className));
40. }
41. }
It seems to me that this primary key of unitsid could not get by mapping
Any solution would be appreciated
First I think you haven't understand the ORM (object relational mapping) concept in your entities you don't map these relations by foreign keys, doctrine will do it for you, in the entities layer you have to map objects and only objects
Second you need to map your entities relations by using orm annotations or xml configuration to describe those relations if they are oneToOne or ManyToOne or OneToMany or ManyToMany relation
Third You are having this error because you haven't set a value to the entity id, to do that you have two options : auto generate the id or set it manually before persisting object
see this
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
I have a weird problem when I want to generate my database schema on Symfony2, one attribut is not accepted...
The annotation "#Doctrine\ORM\Mapping\ManyToOne" in property L3L2\EntraideBundle\Entity\RendezVous::$idDispoProf does not exist, or could not be auto-loaded.
It's even weirder because its working on MacOS X and Windows (Vista & Seven). I tried to make it works on Ubuntu Server VM.
Here is my entities code :
<?php
namespace L3L2\EntraideBundle\Entity;
use L3L2\UserBundle\Entity\User;
use Doctrine\ORM\Mapping as ORM;
/**
* RendezVous
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="L3L2\EntraideBundle\Entity\RendezVousRepository")
*/
class RendezVous
{
/**
* Constructor
*/
public function __construct()
{
$this->vuEleve = "NON";
$this->vuProf = "NON";
}
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="lieu", type="string", length=255)
*/
private $lieu;
/**
* #var string
*
* #ORM\Column(name="statut", type="string", length=255)
*/
private $statut;
/**
* #var \DateTime
*
* #ORM\Column(name="date", type="date")
*/
private $date;
/**
* #var \DateTime
*
* #ORM\Column(name="time", type="time")
*/
private $time;
/**
* #var \DateTime
*
* #ORM\Column(name="datetimeDebut", type="datetime")
*/
private $datetimeDebut;
/**
* #var \DateTime
*
* #ORM\Column(name="datetimeFin", type="datetime")
*/
private $datetimeFin;
//Création de OneToOne vers Evaluation
/**
* #ORM\OneToOne(targetEntity="L3L2\EntraideBundle\Entity\Evaluation", mappedBy="idRdvEval")
* #ORM\JoinColumn(name="id_eval", referencedColumnName="id")
*/
protected $evaluationRdv;
//PROBLEM HERE !!
// Création de ManytoOne vers Disponibilite
/**
* #ORM\ManytoOne(targetEntity="L3L2\EntraideBundle\Entity\Disponibilite")
* #ORM\JoinColumn(name="id_dispo_prof", referencedColumnName="id", onDelete="SET NULL")
*/
protected $idDispoProf;
//Création de ManyToOne vers Cours
/**
* #ORM\ManyToOne(targetEntity="L3L2\EntraideBundle\Entity\Cours", inversedBy="rendezVousCours")
* #ORM\JoinColumn(name="id_cours_rdv", referencedColumnName="id")
*/
protected $idCoursRdv;
//Création de ManyToOne vers User
/**
* #ORM\ManyToOne(targetEntity="L3L2\UserBundle\Entity\User", inversedBy="rendezVousEleve")
* #ORM\JoinColumn(name="id_eleve_rdv", referencedColumnName="id")
*/
protected $idEleveRdv;
/**
* #var string
*
* #ORM\Column(name="vuEleve", type="string", length=255, nullable=true)
*/
private $vuEleve;
/**
* #var string
*
* #ORM\Column(name="vuProf", type="string", length=255, nullable=true)
*/
private $vuProf;
//Création de ManyToOne vers User
/**
* #ORM\ManyToOne(targetEntity="L3L2\UserBundle\Entity\User")
* #ORM\JoinColumn(name="dernierModif", referencedColumnName="id")
*/
private $dernierModif;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set lieu
*
* #param string $lieu
* #return RendezVous
*/
public function setLieu($lieu)
{
$this->lieu = $lieu;
return $this;
}
/**
* Get lieu
*
* #return string
*/
public function getLieu()
{
return $this->lieu;
}
/**
* Set statut
*
* #param string $statut
* #return RendezVous
*/
public function setStatut($statut)
{
$this->statut = $statut;
return $this;
}
/**
* Get statut
*
* #return string
*/
public function getStatut()
{
return $this->statut;
}
/**
* Set evaluationRdv
*
* #param \L3L2\EntraideBundle\Entity\Evaluation $evaluationRdv
* #return RendezVous
*/
public function setEvaluationRdv(\L3L2\EntraideBundle\Entity\Evaluation $evaluationRdv = null)
{
$this->evaluationRdv = $evaluationRdv;
return $this;
}
/**
* Get evaluationRdv
*
* #return \L3L2\EntraideBundle\Entity\Evaluation
*/
public function getEvaluationRdv()
{
return $this->evaluationRdv;
}
/**
* Set idEleveRdv
*
* #param \L3L2\UserBundle\Entity\User $idEleveRdv
* #return RendezVous
*/
public function setIdEleveRdv(\L3L2\UserBundle\Entity\User $idEleveRdv = null)
{
return $this->idEleveRdv = $idEleveRdv;
}
/**
* Get idEleveRdv
*
* #return \L3L2\UserBundle\Entity\User
*/
public function getIdEleveRdv()
{
return $this->idEleveRdv;
}
/**
* Set idDispoProf
*
* #param \L3L2\EntraideBundle\Entity\Disponibilite $idDispoProf
* #return RendezVous
*/
public function setIdDispoProf(\L3L2\EntraideBundle\Entity\Disponibilite $idDispoProf = null)
{
return $this->idDispoProf = $idDispoProf;
}
/**
* Get idDispoProf
*
* #return \L3L2\EntraideBundle\Entity\Disponibilite
*/
public function getIdDispoProf()
{
return $this->idDispoProf;
}
/**
* Set idCoursRdv
*
* #param \L3L2\EntraideBundle\Entity\Cours $idCoursRdv
* #return RendezVous
*/
public function setIdCoursRdv(\L3L2\EntraideBundle\Entity\Cours $idCoursRdv = null)
{
return $this->idCoursRdv = $idCoursRdv;
}
/**
* Get idCoursRdv
*
* #return \L3L2\EntraideBundle\Entity\Cours
*/
public function getIdCoursRdv()
{
return $this->idCoursRdv;
}
/**
* Set date
*
* #param \DateTime $date
* #return RendezVous
*/
public function setDate($date)
{
$this->date = clone $date;
return $this;
}
/**
* Get date
*
* #return \DateTime
*/
public function getDate()
{
return clone $this->date;
}
/**
* Set time
*
* #param \DateTime $time
* #return RendezVous
*/
public function setTime($time)
{
$this->time = clone $time;
return $this;
}
/**
* Get time
*
* #return \DateTime
*/
public function getTime()
{
return clone $this->time;
}
/**
* Set vuEleve
*
* #param string $vuEleve
* #return RendezVous
*/
public function setVuEleve($vuEleve)
{
$this->vuEleve = $vuEleve;
return $this;
}
/**
* Get vuEleve
*
* #return string
*/
public function getVuEleve()
{
return $this->vuEleve;
}
/**
* Set vuProf
*
* #param string $vuProf
* #return RendezVous
*/
public function setVuProf($vuProf)
{
$this->vuProf = $vuProf;
return $this;
}
/**
* Get vuProf
*
* #return string
*/
public function getVuProf()
{
return $this->vuProf;
}
/**
* Set datetimeDebut
*
* #param \DateTime $datetimeDebut
* #return RendezVous
*/
public function setDatetimeDebut($datetimeDebut)
{
$this->datetimeDebut = $datetimeDebut;
return $this;
}
/**
* Get datetimeDebut
*
* #return \DateTime
*/
public function getDatetimeDebut()
{
return $this->datetimeDebut;
}
/**
* Set datetimeFin
*
* #param \DateTime $datetimeFin
* #return RendezVous
*/
public function setDatetimeFin($datetimeFin)
{
$this->datetimeFin = $datetimeFin;
return $this;
}
/**
* Get datetimeFin
*
* #return \DateTime
*/
public function getDatetimeFin()
{
return $this->datetimeFin;
}
/**
* Set dernierModif
*
* #param \L3L2\UserBundle\Entity\User $dernierModif
* #return RendezVous
*/
public function setDernierModif(\L3L2\UserBundle\Entity\User $dernierModif = null)
{
$this->dernierModif = $dernierModif;
return $this;
}
/**
* Get dernierModif
*
* #return \L3L2\UserBundle\Entity\User
*/
public function getDernierModif()
{
return $this->dernierModif;
}
}
If I remove the $idDispoProf or annotations before $idDispoProf I can schema:update...
Any idea ?
You have ManytoOne written in lowercase in this specific property instead of ManyToOne in rest of them. Autoloader works in Windows probably because for this system file called ManyToOne.php and ManytoOne.php is the same - Linux is case sensitive.
So solution for you: change ManytoOne to ManyToOne
I'm trying to add a simple comment entity, with the "postedOn" attribute as a Datetime. Whenever I try to add a comment, I get this error :
Error: Call to undefined method Symfony\Component\Validator\Constraints\DateTime::format() in /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/DateTimeType.php line 53
Any idea ?
Here's the entity code :
<?php
namespace AOFVH\FlyBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Comment
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="AOFVH\FlyBundle\Entity\CommentRepository")
*/
class Comment
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var integer
*
* #ORM\Column(name="rating", type="integer")
*/
private $rating;
/**
* #ORM\Column(type="datetime", nullable=true)
*/
protected $postedon;
/**
* #var string
*
* #ORM\Column(name="text", type="text")
*/
private $text;
/**
* #var $commenter
*
* #ORM\ManyToOne(targetEntity="AOFVH\UserBundle\Entity\User", inversedBy="comments", cascade={"persist", "merge"})
*/
private $commenter;
/**
* #var $commenter
*
* #ORM\ManyToOne(targetEntity="AOFVH\FlyBundle\Entity\Flight", inversedBy="comments", cascade={"persist", "merge"})
*/
private $flight;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set rating
*
* #param integer $rating
* #return Comment
*/
public function setRating($rating)
{
$this->rating = $rating;
return $this;
}
/**
* Get rating
*
* #return integer
*/
public function getRating()
{
return $this->rating;
}
/**
* Set text
*
* #param string $text
* #return Comment
*/
public function setText($text)
{
$this->text = $text;
return $this;
}
/**
* Get text
*
* #return string
*/
public function getText()
{
return $this->text;
}
/**
* Set commenter
*
* #param \AOFVH\UserBundle\Entity\User $commenter
* #return Comment
*/
public function setCommenter(\AOFVH\UserBundle\Entity\User $commenter = null)
{
$this->commenter = $commenter;
return $this;
}
/**
* Get commenter
*
* #return \AOFVH\UserBundle\Entity\User
*/
public function getCommenter()
{
return $this->commenter;
}
/**
* Set flight
*
* #param \AOFVH\FlyBundle\Entity\Flight $flight
* #return Comment
*/
public function setFlight(\AOFVH\FlyBundle\Entity\Flight $flight = null)
{
$this->flight = $flight;
return $this;
}
/**
* Get flight
*
* #return \AOFVH\FlyBundle\Entity\Flight
*/
public function getFlight()
{
return $this->flight;
}
Here are the postedOn getters and setters
/**
* Set postedon
*
* #param \DateTime $postedon
* #return Comment
*/
public function setPostedon($postedon)
{
$this->postedon = $postedon;
return $this;
}
/**
* Get postedon
*
* #return \DateTime
*/
public function getPostedon()
{
return $this->postedon;
}
}
I think it's your mapping in your entity, you don't use "datetime" doctrine format else your form type will try to generate a date with a string for example but for me "postedOn must always be defined on a new comment.You can update your entity constructor with : $this->setPostedOn(new \Datetime()); or you can use TimestampableTrait