I have 3 tables Chat(id + info) User(id + some info) and relation table chat_invited(chatId+userId)
I am using ZF2 and Doctrine2
I have Entity chat:
<?php
namespace Chat\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Chat
*
* #ORM\Table(name="chat")
* #ORM\Entity
*/
class Chat
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="title", type="string", length=256, nullable=true)
*/
private $title;
/**
* #var \DateTime
*
* #ORM\Column(name="created", type="datetime", nullable=false)
*/
private $created;
/**
* #var \Doctrine\Common\Collections\Collection
*
* #ORM\ManyToMany(targetEntity="Chat\Entity\User", inversedBy="chat")
* #ORM\JoinTable(name="chat_invited",
* joinColumns={
* #ORM\JoinColumn(name="chat", referencedColumnName="id")
* },
* inverseJoinColumns={
* #ORM\JoinColumn(name="user", referencedColumnName="id")
* }
* )
*/
private $user;
/**
* #var \Chat\Entity\ChatCategory
*
* #ORM\ManyToOne(targetEntity="Chat\Entity\ChatCategory")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="category", referencedColumnName="id")
* })
*/
private $category;
/**
* #var \Chat\Entity\User
*
* #ORM\ManyToOne(targetEntity="Chat\Entity\User")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="owner", referencedColumnName="id")
* })
*/
private $owner;
/**
* #var \Chat\Entity\Building
*
* #ORM\ManyToOne(targetEntity="Chat\Entity\Building")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="building", referencedColumnName="id")
* })
*/
private $building;
/**
* #var \Chat\Entity\Company
*
* #ORM\ManyToOne(targetEntity="Chat\Entity\Company")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="company", referencedColumnName="id")
* })
*/
private $company;
/**
* Constructor
*/
public function __construct()
{
$this->user = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Add user
*
* #param \Chat\Entity\User $user
* #return Chat
*/
public function addUser(\Chat\Entity\User $user)
{
$this->user[] = $user;
return $this;
}
/**
* Remove user
*
* #param \Chat\Entity\User $user
*/
public function removeUser(\Chat\Entity\User $user)
{
$this->user->removeElement($user);
}
/**
* Get user
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getUser()
{
return $this->user;
}
........................................
}
How find chat which have invited User1 and User2 to him?
Its worked for me
$qb = $em->createQueryBuilder();
$query = $qb->select('chats, user')
->from('Chat\Entity\Chat', 'chats')
->join('chats.user', 'user')
->join('chats.user', 'user2')
->where('user.id = :user AND user2.id = :inv ')
->setParameter('user', <User1.id>)
->setParameter('inv',<User2.id>)
->setMaxResults(1)
->getQuery();
Related
I have an entity called Materials with 8 associated entities (with join tables).
When I submit the form to update existing entities/records in the database, it takes up to 24 seconds to finish the process. I read somewhere that I shouldn't use:
$em = $this->getDoctrine()->getManager();
$form->handleRequest($request);
$data = $form->getData();
$em->persist($data);
$em->flush();
Because multiple entities would take too long to persist, but to boost performance I should use the update query:
Exp.
$em = $this->getDoctrine()->getManager();
$repo = $em->getRepository('ourcodeworldBundle:Posts');
$newCreatedAt = new \DateTime();
$qb = $repo->createQueryBuilder('p');
$qb->update()
->set('p.createdAt', ':newCreatedAt')
->setParameter('newCreatedAt', $newCreatedAt);
$qb->getQuery()->execute();
https://ourcodeworld.com/articles/read/2/5-simple-tips-for-boost-the-database-handling-with-symfony2-and-doctrine
Does anybody know if that is correct and if so, will I have to really update every entity manually? It will take me a long time to write this as queries, since there are so many.
I found the problem.
The form used to fail at $form->handleRequest($request); in my controller:
if ($request->getMethod() == 'POST') {
$req = $request->request->get("material");
$form->handleRequest($request);
...
}
But the real problem was that my Assert statements in my Material class were not well defined. As soon as I corrected them handleRequest no longer slowed down the form submission process.
Here is my updated Material class with the fixed Assert statements:
/**
* #ORM\Table(name="materials")
* #ORM\Entity(repositoryClass="AppBundle\Entity\MaterialRepository")
*/
class Material
{
/**
* #var integer
*
* #ORM\Column(name="materialID", type="integer", nullable=true)
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $materialID;
/**
* #var integer
*
* #Assert\Type("\integer")
* #ORM\Column(name="lrcID", type="integer", nullable=true)
*/
private $lrcID;
/**
* #var string
*
* #Assert\Type("\string")
* #Assert\Length(max=255)
* #ORM\Column(name="title", type="string", length=255, nullable=false)
*/
private $title;
/**
* #var string
*
* #Assert\Type("\string")
* #ORM\Column(name="description", type="text", nullable=false)
*/
private $description;
/**
* #var string
*
* #Assert\Type("\string")
* #Assert\Length(max=255)
* #ORM\Column(name="author", type="string", length=255, nullable=true)
*/
private $author;
/**
* #var integer
*
* #Assert\Type("\integer")
* #ORM\Column(name="year", type="integer", nullable=true)
*/
private $year;
/**
* #var File
*
* #Assert\File(
* maxSize = "10M",
* mimeTypes = {"image/jpeg", "image/gif", "image/png", "image/tiff"},
* maxSizeMessage = "The maxmimum allowed file size is 10MB.",
* mimeTypesMessage = "Please, upload the imag as a jpge, gif, png, or tiff file."
* )
* #ORM\Column(name="image", type="string", length=100, nullable=true)
*/
private $image;
/**
* #var \DateTime
*
* #Assert\NotBlank()
* #Assert\Type("\DateTime")
* #ORM\Column(name="dateModified", type="datetime", nullable=true)
*/
private $dateModified;
/**
* #var integer
*
* #Assert\Type("\integer")
* #ORM\Column(name="isActive", type="integer", nullable=true)
*/
private $isActive;
/**
* #var integer
*
* #Assert\Type("\integer")
* #ORM\Column(name="isFree", type="integer", nullable=true)
*/
private $isFree;
/**
* #var integer
*
* #Assert\Type("\integer")
* #ORM\Column(name="sizevalue", type="integer", nullable=true)
*/
private $sizevalue;
/**
* #var integer
*
* #Assert\Type("\integer")
* #ORM\Column(name="sizeunit", type="integer", nullable=true)
*/
private $sizeunit;
/**
* #var integer
*
* #Assert\Type("\integer")
* #ORM\Column(name="isComplete", type="integer", nullable=true)
*/
private $isComplete;
/**
*
* #Assert\Url(
* checkDNS = true,
* message = "The url '{{ value }}' is not a valid url",
* dnsMessage = "The host '{{ value }}' could not be resolved.",
* )
* #Assert\Length(max=255)
* #ORM\Column(name="url", type="string", length=255, nullable=false)
*/
private $url;
/**
* #Assert\Type(type="AppBundle\Entity\MaterialLanguage")
* #Assert\Valid()
* #ORM\ManyToMany(targetEntity="MaterialLanguage", inversedBy="material")
* #ORM\JoinTable(name="materials_language_map",
* joinColumns={#ORM\JoinColumn(name="materialID", referencedColumnName="materialID", nullable=false)},
* inverseJoinColumns={#ORM\JoinColumn(name="languageID", referencedColumnName="languageID", nullable=false)})
*/
public $materiallanguage;
/**
* #Assert\Type(type="AppBundle\Entity\MaterialType")
* #Assert\Valid()
* #ORM\ManyToMany(targetEntity="MaterialType", inversedBy="material")
* #ORM\JoinTable(name="materials_type_map",
* joinColumns={#ORM\JoinColumn(name="materialID", referencedColumnName="materialID", nullable=false)},
* inverseJoinColumns={#ORM\JoinColumn(name="typeID", referencedColumnName="typeID", nullable=false)})
*/
public $materialtype;
/**
* #Assert\Type(type="AppBundle\Entity\MaterialAudience")
* #Assert\Valid()
* #ORM\ManyToMany(targetEntity="MaterialAudience", inversedBy="material")
* #ORM\JoinTable(name="materials_audience_map",
* joinColumns={#ORM\JoinColumn(name="materialID", referencedColumnName="materialID", nullable=false)},
* inverseJoinColumns={#ORM\JoinColumn(name="audienceID", referencedColumnName="audienceID", nullable=false)})
*/
public $materialaudience;
/**
* #Assert\Type(type="AppBundle\Entity\MaterialLevel")
* #Assert\Valid()
* #ORM\ManyToMany(targetEntity="MaterialLevel", inversedBy="material")
* #ORM\JoinTable(name="materials_level_map",
* joinColumns={#ORM\JoinColumn(name="materialID", referencedColumnName="materialID", nullable=false)},
* inverseJoinColumns={#ORM\JoinColumn(name="levelID", referencedColumnName="levelID", nullable=false)})
*/
public $materiallevel;
/**
* #Assert\Type(type="AppBundle\Entity\MaterialFormat")
* #Assert\Valid()
* #ORM\ManyToMany(targetEntity="MaterialFormat")
* #ORM\JoinTable(name="materials_format_map",
* joinColumns={#ORM\JoinColumn(name="materialID", referencedColumnName="materialID", nullable=false)},
* inverseJoinColumns={#ORM\JoinColumn(name="formatid", referencedColumnName="formatid", nullable=false)})
*/
public $materialformat;
/**
* #Assert\Type(type="AppBundle\Entity\MaterialSpecificMedium")
* #Assert\Valid()
* #ORM\ManyToMany(targetEntity="MaterialSpecificMedium")
* #ORM\JoinTable(name="materials_specificmedium_map",
* joinColumns={#ORM\JoinColumn(name="materialID", referencedColumnName="materialID", nullable=false)},
* inverseJoinColumns={#ORM\JoinColumn(name="specificmediumID", referencedColumnName="specificmediumid", nullable=false)})
*/
public $materialspecificmedium;
/**
* #Assert\Type(type="AppBundle\Entity\MaterialSizeUnits")
* #Assert\Valid()
* #ORM\ManyToOne(targetEntity="MaterialSizeUnits", inversedBy="material")
* #ORM\JoinColumn(name="sizeunit", referencedColumnName="id", nullable=true)
*/
public $materialsizeunits;
/**
* #Assert\Type(type="AppBundle\Entity\MaterialCategory")
* #Assert\Valid()
* #ORM\ManyToMany(targetEntity="MaterialCategory")
* #ORM\JoinTable(name="materials_category_map",
* joinColumns={#ORM\JoinColumn(name="materialID", referencedColumnName="materialID", nullable=false)},
* inverseJoinColumns={#ORM\JoinColumn(name="categoryID", referencedColumnName="categoryID", nullable=false)})
*/
public $materialcategory;
/**
* #Assert\Type(type="AppBundle\Entity\MaterialKeyword")
* #Assert\Valid()
* #ORM\ManyToMany(targetEntity="MaterialKeyword", inversedBy="material")
* #ORM\JoinTable(name="materials_keyword_map",
* joinColumns={#ORM\JoinColumn(name="materialID", referencedColumnName="materialID", nullable=false)},
* inverseJoinColumns={#ORM\JoinColumn(name="keywordID", referencedColumnName="id", nullable=false)})
*/
public $materialkeyword;
/**
* #Assert\Type(type="AppBundle\Entity\MaterialYear")
* #Assert\Valid()
* #ORM\ManyToOne(targetEntity="MaterialYear")
* #ORM\JoinColumn(name="year", referencedColumnName="yearID")
*/
public $materialyear;
/**
* #Assert\Type(type="AppBundle\Entity\Lrc")
* #Assert\Valid()
* #ORM\ManyToOne(targetEntity="Lrc", inversedBy="material")
* #ORM\JoinColumn(name="lrcID", referencedColumnName="id")
*/
public $lrc;
/**
* Constructor
*/
public function __construct()
{
$this->MaterialLanguage = new ArrayCollection();
$this->MaterialType = new ArrayCollection();
$this->MaterialLevel = new ArrayCollection();
$this->MaterialAudience = new ArrayCollection();
$this->MaterialFormat = new ArrayCollection();
$this->MaterialSpecificMedium = new ArrayCollection();
$this->MaterialSizeUnits = new ArrayCollection();
$this->MaterialCategory = new ArrayCollection();
$this->MaterialKeyword = new ArrayCollection();
$this->MaterialYear = new ArrayCollection();
$this->Lrc = new ArrayCollection();
}
/**
* Set materiallanguage
*
* #param array $materiallanguage
*
*/
public function setMateriallanguage(ArrayCollection $materiallanguage)
{
$this->materiallanguage = $materiallanguage;
}
/**
* Get materiallanguage
*
* #Assert\Type("\array")
* #return array
*/
public function getMateriallanguage()
{
return $this->materiallanguage;
}
/**
* Set materialtype
*
* #param array $materialtype
*
*/
public function setMaterialtype(ArrayCollection $materialtype)
{
$this->materialtype = $materialtype;
}
/**
* Get materialtype
*
* #Assert\Type("\array")
* #return array
*/
public function getMaterialtype()
{
return $this->materialtype;
}
/**
* Set materialaudience
*
* #param array $materialaudience
*
*/
public function setMaterialaudience(ArrayCollection $materialaudience)
{
$this->materialaudience = $materialaudience;
}
/**
* Get materialaudience
*
* #Assert\Type("\array")
* #return array
*/
public function getMaterialaudience()
{
return $this->materialaudience;
}
/**
* Set materialformat
*
* #param array $materialformat
*
*/
public function setMaterialformat(ArrayCollection $materialformat)
{
$this->materialformat = $materialformat;
}
/**
* Get materialformat
*
* #Assert\Type("\array")
* #return array
*/
public function getMaterialformat()
{
return $this->materialformat;
}
/**
* Set materialspecificmedium
*
* #param array $materialspecificmedium
*
*/
public function setMaterialspecificmedium(ArrayCollection $materialspecificmedium)
{
$this->materialspecificmedium = $materialspecificmedium;
}
/**
* Get materialspecificmedium
*
* #Assert\Type("\array")
* #return array
*/
public function getMaterialspecificmedium()
{
return $this->materialspecificmedium;
}
/**
* Set materiallevel
*
* #param array $materiallevel
*
*/
public function setMateriallevel(ArrayCollection $materiallevel)
{
$this->materiallevel = $materiallevel;
}
/**
* Get materiallevel
*
* #Assert\Type("\array")
* #return array
*/
public function getMateriallevel()
{
return $this->materiallevel;
}
/**
* Set materialsizeunits
*
* #param array $materialsizeunits
*
*/
public function setMaterialsizeunits(MaterialSizeUnits $materialsizeunits)
{
$this->materialsizeunits = $materialsizeunits;
}
/**
* Get materialsizeunits
*
* #return array
*/
public function getMaterialsizeunits()
{
return $this->materialsizeunits;
}
/**
* Set materialcategory
*
* #param array $materialcategory
*
*/
public function setMaterialcategory(ArrayCollection $materialcategory)
{
$this->materialcategory = $materialcategory;
}
/**
* Get materialcategory
*
* #Assert\Type("\array")
* #return array
*/
public function getMaterialcategory()
{
return $this->materialcategory;
}
/**
* Set materialkeyword
*
* #param array $materialkeyword
*
*/
public function setMaterialkeyword(MaterialKeyword $materialkeyword)
{
$this->materialkeyword = $materialkeyword;
}
/**
* Get materialkeyword
*
* #Assert\Type("\array")
* #return array
*/
public function getMaterialkeyword()
{
return $this->materialkeyword;
}
/**
* Set materialyear
*
* #param array $materialyear
*
*/
public function setMaterialyear(MaterialYear $materialyear)
{
$this->materialyear = $materialyear;
}
/**
* Get materiallamaterialyear
*
* #Assert\Type("\array")
* #return array
*/
public function getMaterialyear()
{
return $this->materialyear;
}
/**
* Set lrc
*
* #param array $lrc
*
*/
public function setLrc(Lrc $lrc=null)
{
$this->lrc = $lrc;
}
/**
* Get lrc
*
* #Assert\Type("\array")
* #return array
*/
public function getLrc()
{
return $this->lrc;
}
/**
* Set materialID
*
* #param integer $materialID
*
* #return Material
*/
public function setMaterialID($materialID)
{
$this->materialID = $materialID;
return $this;
}
/**
* Get materialID
*
* #return integer
*/
public function getMaterialID()
{
return $this->materialID;
}
/**
* Set lrcID
*
* #param integer $lrcID
*
* #return Material
*/
public function setLrcID($lrcID)
{
$this->lrcID = $lrcID;
return $this;
}
/**
* Get lrcID
*
* #return integer
*/
public function getLrcID()
{
return $this->lrcID;
}
/**
* Set title
*
* #param string $title
*
* #return Material
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* #return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set description
*
* #param string $description
*
* #return Material
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* #return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set author
*
* #param string $author
*
* #return Material
*/
public function setAuthor($author)
{
$this->author = $author;
return $this;
}
/**
* Get author
*
* #return string
*/
public function getAuthor()
{
return $this->author;
}
/**
* Set year
*
* #param integer $year
*
* #return Material
*/
public function setYear($year)
{
$this->year = $year;
return $this;
}
/**
* Get year
*
* #return integer
*/
public function getYear()
{
return $this->year;
}
/**
* Set image
*
* #param string $image
*
* #return Material
*/
public function setImage($image)
{
$this->image = $image;
return $this;
}
/**
* Get image
*
* #return string
*/
public function getImage()
{
return $this->image;
}
/**
* Set dateModified
*
* #param \DateTime $dateModified
*
* #return Material
*/
public function setDateModified(\DateTime $dateModified)
{
$this->dateModified = $dateModified;
return $this;
}
/**
* Get dateModified
*
* #return \DateTime
*/
public function getDateModified()
{
return $this->dateModified;
}
/**
* Set isActive
*
* #param integer $isActive
*
* #return Material
*/
public function setIsActive($isActive)
{
$this->isActive = $isActive;
return $this;
}
/**
* Get isActive
*
* #return integer
*/
public function getIsActive()
{
return $this->isActive;
}
/**
* Set isFree
*
* #param integer $isFree
*
* #return Material
*/
public function setIsFree($isFree)
{
$this->isFree = $isFree;
return $this;
}
/**
* Get isFree
*
* #return integer
*/
public function getIsFree()
{
return $this->isFree;
}
/**
* Set sizevalue
*
* #param integer $sizevalue
*
*/
public function setSizevalue($sizevalue)
{
$this->sizevalue = $sizevalue;
}
/**
* Get sizevalue
*
* #return integer
*/
public function getSizevalue()
{
return $this->sizevalue;
}
/**
* Set sizeunit
*
* #param integer $sizeunit
*
* #return Material
*/
public function setSizeunit($sizeunit)
{
$this->sizeunit = $sizeunit;
return $this;
}
/**
* Get sizeunit
*
* #return integer
*/
public function getSizeunit()
{
return $this->sizeunit;
}
/**
* Set isComplete
*
* #param integer $isComplete
*
* #return Material
*/
public function setIsComplete($isComplete)
{
$this->isComplete = $isComplete;
return $this;
}
/**
* Get isComplete
*
* #return integer
*/
public function getIsComplete()
{
return $this->isComplete;
}
/**
* Set url
*
* #param string $url
*
* #return Material
*/
public function setUrl($url)
{
$this->url = $url;
return $this;
}
/**
* Get url
*
* #return string
*/
public function getUrl()
{
return $this->url;
}
}
Using Symfony 3.3.13 for an API
I have LigneCommande and Commande entities, where a Commande is linked to a LigneCommande.
LigneCommande.php has the following code:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as JMS;
/**
* LigneCommande
*
* #ORM\Table(name="ligne_commande")
* #ORM\Entity(repositoryClass="AppBundle\Repository\LigneCommandeRepository")
*/
class LigneCommande
{
/**
* #var int
*
* #JMS\Groups({"listeLigneCommandes", "detailLigneCommande"})
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #var Commande
*
* #JMS\Groups({"listeLigneCommandes", "detailLigneCommande"})
*
* Many LigneCommande have One numeroCommande.
* #ORM\ManyToOne(targetEntity="Commande", inversedBy="lignes", cascade={"all"}, fetch="EAGER")
*/
protected $commande;
/**
* #var Article
*
* #JMS\Groups({"listeLigneCommandes", "detailLigneCommande"})
*
* Many LigneCommande have One codeArticle.
* #ORM\ManyToOne(targetEntity="Article", inversedBy="lignes", cascade={"all"}, fetch="EAGER")
*/
protected $article;
/**
* #var string
*
* #JMS\Groups({"listeLigneCommandes", "detailLigneCommande"})
*
* #ORM\Column(name="libelle", type="string", length=255)
*/
protected $libelle;
/**
* #var string
*
* #JMS\Groups({"listeLigneCommandes", "detailLigneCommande"})
*
* #ORM\Column(name="unite", type="string", length=255)
*/
protected $unite;
/**
* #var float
*
* #JMS\Groups({"listeLigneCommandes", "detailLigneCommande"})
*
* #ORM\Column(name="qte_commande", type="float")
*/
protected $qteCommande;
/**
* #var float
*
* #JMS\Groups({"listeLigneCommandes", "detailLigneCommande"})
*
* #ORM\Column(name="qte_recue", type="float")
*/
protected $qteRecue;
/**
* #var float
*
* #JMS\Groups({"listeLigneCommandes", "detailLigneCommande"})
*
* #ORM\Column(name="qte_arecevoir", type="float")
*/
protected $qteArecevoir;
/**
* #var float
*
* #JMS\Groups({"listeLigneCommandes", "detailLigneCommande"})
*
* #ORM\Column(name="identifiant", type="float", unique=true)
*/
protected $identifiant;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set commande
*
* #param Commande $commande
*
* #return LigneCommande
*/
public function setCommande(Commande $commande)
{
$this->numero = $commande;
return $this;
}
/**
* Get commande
*
* #return Commande
*/
public function getCommande()
{
return $this->commande;
}
/**
* Set article
*
* #param Article $article
*
* #return LigneCommande
*/
public function setArticle(Article $article)
{
$this->article = $article;
return $this;
}
/**
* Get article
*
* #return Article
*/
public function getArticle()
{
return $this->article;
}
/**
* Set libelle
*
* #param string $libelle
*
* #return LigneCommande
*/
public function setLibelle($libelle)
{
$this->libelle = $libelle;
return $this;
}
/**
* Get libelle
*
* #return string
*/
public function getLibelle()
{
return $this->libelle;
}
/**
* Set unite
*
* #param string $unite
*
* #return LigneCommande
*/
public function setUnite($unite)
{
$this->unite = $unite;
return $this;
}
/**
* Get unite
*
* #return string
*/
public function getUnite()
{
return $this->unite;
}
/**
* Set qteCommande
*
* #param float $qteCommande
*
* #return LigneCommande
*/
public function setQteCommande($qteCommande)
{
$this->qteCommande = $qteCommande;
return $this;
}
/**
* Get qteCommande
*
* #return float
*/
public function getQteCommande()
{
return $this->qteCommande;
}
/**
* Set qteRecue
*
* #param float $qteRecue
*
* #return LigneCommande
*/
public function setQteRecue($qteRecue)
{
$this->qteRecue = $qteRecue;
return $this;
}
/**
* Get qteRecue
*
* #return float
*/
public function getQteRecue()
{
return $this->qteRecue;
}
/**
* Set qteArecevoir
*
* #param float $qteArecevoir
*
* #return LigneCommande
*/
public function setQteArecevoir($qteArecevoir)
{
$this->qteArecevoir = $qteArecevoir;
return $this;
}
/**
* Get qteArecevoir
*
* #return float
*/
public function getQteArecevoir()
{
return $this->qteArecevoir;
}
/**
* Set identifiant
*
* #param float $identifiant
*
* #return LigneCommande
*/
public function setIdentifiant($identifiant)
{
$this->identifiant = $identifiant;
return $this;
}
/**
* Get identifiant
*
* #return float
*/
public function getIdentifiant()
{
return $this->identifiant;
}
}
Commande.php has the following code:
<?php
namespace AppBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as JMS;
/**
* Commande
*
* #ORM\Table(name="commande")
* #ORM\Entity(repositoryClass="AppBundle\Repository\CommandeRepository")
*/
class Commande
{
/**
* #var int
*
* #JMS\Groups({"listeCommandes"})
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #JMS\Groups({"listeCommandes", "detailCommande"})
*
* #ORM\Column(name="numero", type="string", length=8, unique=true)
*/
private $numero;
/**
* #var \DateTime
*
* #JMS\Groups({"listeCommandes", "detailCommande"})
*
* #ORM\Column(name="date", type="date")
*/
private $date;
/**
* #var int
*
* #JMS\Groups({"listeCommandes", "detailCommande"})
*
* #ORM\Column(name="chantier_id", type="integer")
*
* Many Commande have One chantierCode.
* #ORM\ManyToOne(targetEntity="Chantier")
* #ORM\JoinColumn(name="chantier_id", referencedColumnName="id")
*/
private $chantier;
/**
* #var string
*
* #JMS\Groups({"listeCommandes", "detailCommande"})
*
* #ORM\Column(name="fournisseur_code", type="string", length=7)
*/
private $fournisseurCode;
/**
* #var string
*
* #JMS\Groups({"listeCommandes", "detailCommande"})
*
* #ORM\Column(name="fournisseur_nom", type="string", length=255)
*/
private $fournisseurNom;
/**
* #var string
*
* #JMS\Groups({"listeCommandes", "detailCommande"})
*
* #ORM\Column(name="redacteur_code", type="string", length=5)
*/
private $redacteurCode;
/**
* #var string
*
* #JMS\Groups({"listeCommandes", "detailCommande"})
*
* #ORM\Column(name="secteur_code", type="string", length=1, nullable=true)
*/
private $secteurCode;
/**
* #var string
*
* #JMS\Groups({"listeCommandes", "detailCommande"})
*
* #ORM\Column(name="livraison_nom", type="string", length=255)
*/
private $livraisonNom;
/**
* #var string
*
* #JMS\Groups({"listeCommandes", "detailCommande"})
*
* #ORM\Column(name="livraison_adresse", type="string", length=255)
*/
private $livraisonAdresse;
/**
* #var string
*
* #JMS\Groups({"listeCommandes", "detailCommande"})
*
* #ORM\Column(name="livraison_cp", type="string", length=5)
*/
private $livraisonCp;
/**
* #var string
*
* #JMS\Groups({"listeCommandes", "detailCommande"})
*
* #ORM\Column(name="livraison_ville", type="string", length=255)
*/
private $livraisonVille;
/**
* #var Collection
*
* #ORM\OneToMany(targetEntity="LigneCommande", mappedBy="commande")
*/
protected $lignes;
public function __construct() {
$this->lignes = new ArrayCollection();
}
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set numero
*
* #param string $numero
*
* #return Commande
*/
public function setNumero($numero)
{
$this->numero = $numero;
return $this;
}
/**
* Get numero
*
* #return string
*/
public function getNumero()
{
return $this->numero;
}
/**
* Set date
*
* #param \DateTime $date
*
* #return Commande
*/
public function setDate($date)
{
$this->date = $date;
return $this;
}
/**
* Get date
*
* #return \DateTime
*/
public function getDate()
{
return $this->date;
}
/**
* Set chantier
*
* #param int $chantier
*
* #return Commande
*/
public function setChantier($chantier)
{
$this->chantier = $chantier;
return $this;
}
/**
* Get chantier
*
* #return int
*/
public function getChantier()
{
return $this->chantier;
}
/**
* Set fournisseurCode
*
* #param string $fournisseurCode
*
* #return Commande
*/
public function setFournisseurCode($fournisseurCode)
{
$this->fournisseurCode = $fournisseurCode;
return $this;
}
/**
* Get fournisseurCode
*
* #return string
*/
public function getFournisseurCode()
{
return $this->fournisseurCode;
}
/**
* Set fournisseurNom
*
* #param string $fournisseurNom
*
* #return Commande
*/
public function setFournisseurNom($fournisseurNom)
{
$this->fournisseurNom = $fournisseurNom;
return $this;
}
/**
* Get fournisseurNom
*
* #return string
*/
public function getFournisseurNom()
{
return $this->fournisseurNom;
}
/**
* Set redacteurCode
*
* #param string $redacteurCode
*
* #return Commande
*/
public function setRedacteurCode($redacteurCode)
{
$this->redacteurCode = $redacteurCode;
return $this;
}
/**
* Get redacteurCode
*
* #return string
*/
public function getRedacteurCode()
{
return $this->redacteurCode;
}
/**
* Set secteurCode
*
* #param string $secteurCode
*
* #return Commande
*/
public function setSecteurCode($secteurCode)
{
$this->secteurCode = $secteurCode;
return $this;
}
/**
* Get secteurCode
*
* #return string
*/
public function getSecteurCode()
{
return $this->secteurCode;
}
/**
* Set livraisonNom
*
* #param string $livraisonNom
*
* #return Commande
*/
public function setLivraisonNom($livraisonNom)
{
$this->livraisonNom = $livraisonNom;
return $this;
}
/**
* Get livraisonNom
*
* #return string
*/
public function getLivraisonNom()
{
return $this->livraisonNom;
}
/**
* Set livraisonAdresse
*
* #param string $livraisonAdresse
*
* #return Commande
*/
public function setLivraisonAdresse($livraisonAdresse)
{
$this->livraisonAdresse = $livraisonAdresse;
return $this;
}
/**
* Get livraisonAdresse
*
* #return string
*/
public function getLivraisonAdresse()
{
return $this->livraisonAdresse;
}
/**
* Set livraisonCp
*
* #param string $livraisonCp
*
* #return Commande
*/
public function setLivraisonCp($livraisonCp)
{
$this->livraisonCp = $livraisonCp;
return $this;
}
/**
* Get livraisonCp
*
* #return string
*/
public function getLivraisonCp()
{
return $this->livraisonCp;
}
/**
* Set livraisonVille
*
* #param string $livraisonVille
*
* #return Commande
*/
public function setLivraisonVille($livraisonVille)
{
$this->livraisonVille = $livraisonVille;
return $this;
}
/**
* Get livraisonVille
*
* #return string
*/
public function getLivraisonVille()
{
return $this->livraisonVille;
}
/**
* #return Collection
*/
public function getLignes() {
return $this->lignes;
}
}
LigneCommandeController.php has the following code:
/**
* #Rest\View(serializerGroups={"detailLigneCommande"})
* #Rest\Get(
* path = "/ligneCommandes/{id}",
* name = "show_ligne_commande",
* requirements = {"id"="\d+"}
* )
*/
public function getLigneCommandeAction(Request $request)
{
$ligneCommande = $this->getDoctrine()
->getRepository('AppBundle:LigneCommande')
->find($request->get('id'));
/* #var $ligneCommande LigneCommande */
$ligneCommande->getCommande();
if (empty($ligneCommande)) {
return View::create(['message' => 'Ligne de commande introuvable'], Response::HTTP_OK);
} else {
return $ligneCommande;
}
}
So in my API when I call localhost:8000/ligneCommandes/1 with the fetch 'EAGER' attribute I hope get something like that :
{
"id": 1,
"commande": {
"numero": "CF000001",
"date": "2017-10-13T00:00:00+00:00",
"chantier": 1,
"fournisseur_code": "F000001",
"fournisseur_nom": "Fournisseur A",
"redacteur_code": "FTOMA",
"secteur_code": "1",
"livraison_nom": "Nom livraison",
"livraison_adresse": "Adresse livraison",
"livraison_cp": "74940",
"livraison_ville": "Ville livraison"
},
"article": {},
"libelle": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
"unite": "TL",
"qte_commande": 10,
"qte_recue": 8,
"qte_arecevoir": 2,
"identifiant": 1
}
But I get this :
{
"id": 1,
"commande": {},
"article": {},
"libelle": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
"unite": "TL",
"qte_commande": 10,
"qte_recue": 8,
"qte_arecevoir": 2,
"identifiant": 1
}
I don't really know why, even with the fetch EAGER method, the object still load as proxy.
Thanks you for your help :)
Ok I found a solution.
Just remove the serializer groups and it's works.
I have a problem. I moved website to another hosting(so I exported DB and imported to new hosting).
But now, when I trying to add new record to database. I have an error stn like ID 1 already exist. But I have almost 500 records in the table.
What can I do to fix it?
Sorry I've should provide more information:
I exported and imported database through phppgadmin I didn't use migrations bundle.
Here is my entity:
class Products
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="serial_number", type="string", length=255, nullable=true)
*/
private $serial;
/**
* #var string
* #Expose
* #ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* #var string
* #Expose
* #ORM\Column(name="url", type="string", length=255)
*/
private $url;
/**
* #var string
* #ORM\Column(name="note", type="text", nullable=true)
*/
private $note;
/**
* #var int
*
* #ORM\Column(name="views", type="bigint", nullable=true)
*/
private $views;
/**
* #ORM\ManyToMany(targetEntity="Models")
* #ORM\JoinTable(name="products_models",
* joinColumns={#ORM\JoinColumn(name="product_id", referencedColumnName="id")},
* inverseJoinColumns={#ORM\JoinColumn(name="model_id", referencedColumnName="id")}
* )
*/
private $models;
/**
* #ORM\OneToOne(targetEntity="ProductDetails", cascade={"persist", "remove"})
* #ORM\JoinColumn(name="details_id", referencedColumnName="id")
*/
private $details;
/**
* #var File
* #Expose
* #ORM\OneToMany(targetEntity="ProductImages", mappedBy="product", cascade={"persist", "remove"})
* #ORM\OrderBy({"id" = "ASC"})
*
*/
private $images;
/**
* #var File
*
* #ORM\OneToMany(targetEntity="Cart", mappedBy="productId", cascade={"persist"})
*
*/
private $cart;
/**
* #var string
*
* #ORM\Column(name="price", type="integer", length=255, nullable=true)
*/
private $price;
/**
* #var string
*
* #ORM\Column(name="bought_price", type="integer", length=255, nullable=true)
*/
private $boughtPrice;
/**
* #var string
*
* #ORM\Column(name="old_price", type="integer", length=255, nullable=true)
*/
private $oldPrice;
/**
* #var bool
*
* #ORM\Column(name="is_active", type="boolean", nullable=true)
*/
private $isActive;
/**
* #var bool
*
* #ORM\Column(name="is_accessory", type="boolean", nullable=true)
*/
private $isAccessory;
/**
* #ORM\ManyToOne(targetEntity="AccessoryCategory")
* #ORM\JoinColumn(name="accessory_category_id", referencedColumnName="id")
*/
private $accessoryCategory;
/**
* #var bool
*
* #ORM\Column(name="is_special", type="boolean", nullable=true)
*/
private $isSpecial;
/**
* #var integer
*
* #ORM\Column(name="quantity", type="integer", nullable=true)
*/
private $quantity;
/**
* created Time/Date
*
* #var \DateTime
*
* #ORM\Column(name="created_at", type="datetime", nullable=false)
*/
protected $createdAt;
/**
* updated Time/Date
*
* #var \DateTime
*
* #ORM\Column(name="updated_at", type="datetime", nullable=false)
*/
protected $updatedAt;
/**
* #var boolean
*
* #ORM\Column(name="seller", type="boolean", length=255, nullable=true)
*/
private $seller;
/**
* Set createdAt
*
* #ORM\PrePersist
*/
public function setCreatedAt()
{
$this->createdAt = new \DateTime();
$this->updatedAt = new \DateTime();
}
/**
* Get createdAt
*
* #return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set updatedAt
*
* #ORM\PreUpdate
*/
public function setUpdatedAt()
{
$this->updatedAt = new \DateTime();
}
/**
* Get updatedAt
*
* #return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* #param string $title
*
* #return Products
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* #return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set url
*
* #param string $url
*
* #return Products
*/
public function setUrl($url)
{
$this->url = $url;
return $this;
}
/**
* Get url
*
* #return string
*/
public function getUrl()
{
return $this->url;
}
/**
* Set note
*
* #param string $note
*
* #return Products
*/
public function setNote($note)
{
$this->note = $note;
return $this;
}
/**
* Get note
*
* #return string
*/
public function getNote()
{
return $this->note;
}
/**
* Set views
*
* #param integer $views
*
* #return Products
*/
public function setViews($views)
{
$this->views = $views;
return $this;
}
/**
* Get views
*
* #return integer
*/
public function getViews()
{
return $this->views;
}
/**
* Set price
*
* #param integer $price
*
* #return Products
*/
public function setPrice($price)
{
$this->price = $price;
return $this;
}
/**
* Get price
*
* #return integer
*/
public function getPrice()
{
return $this->price;
}
/**
* Set boughtPrice
*
* #param integer $boughtPrice
*
* #return Products
*/
public function setBoughtPrice($boughtPrice)
{
$this->boughtPrice = $boughtPrice;
return $this;
}
/**
* Get boughtPrice
*
* #return integer
*/
public function getBoughtPrice()
{
return $this->boughtPrice;
}
/**
* Set isActive
*
* #param boolean $isActive
*
* #return Products
*/
public function setIsActive($isActive)
{
$this->isActive = $isActive;
return $this;
}
/**
* Get isActive
*
* #return boolean
*/
public function getIsActive()
{
return $this->isActive;
}
/**
* Set isAccessory
*
* #param boolean $isAccessory
*
* #return Products
*/
public function setIsAccessory($isAccessory)
{
$this->isAccessory = $isAccessory;
return $this;
}
/**
* Get isAccessory
*
* #return boolean
*/
public function getIsAccessory()
{
return $this->isAccessory;
}
/**
* Set quantity
*
* #param integer $quantity
*
* #return Products
*/
public function setQuantity($quantity)
{
$this->quantity = $quantity;
return $this;
}
/**
* Get quantity
*
* #return integer
*/
public function getQuantity()
{
return $this->quantity;
}
/**
* Set details
*
* #param \Web\AdminBundle\Entity\ProductDetails $details
*
* #return Products
*/
public function setDetails(\Web\AdminBundle\Entity\ProductDetails $details = null)
{
$this->details = $details;
return $this;
}
/**
* Get details
*
* #return \Web\AdminBundle\Entity\ProductDetails
*/
public function getDetails()
{
return $this->details;
}
/**
* Add image
*
* #param \Web\AdminBundle\Entity\ProductImages $image
*
* #return Products
*/
public function addImage(\Web\AdminBundle\Entity\ProductImages $image)
{
$this->images[] = $image;
return $this;
}
/**
* Remove image
*
* #param \Web\AdminBundle\Entity\ProductImages $image
*/
public function removeImage(\Web\AdminBundle\Entity\ProductImages $image)
{
$this->images->removeElement($image);
}
/**
* Get images
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getImages()
{
return $this->images;
}
/**
* Add cart
*
* #param \Web\AdminBundle\Entity\Cart $cart
*
* #return Products
*/
public function addCart(\Web\AdminBundle\Entity\Cart $cart)
{
$this->cart[] = $cart;
return $this;
}
/**
* Remove cart
*
* #param \Web\AdminBundle\Entity\Cart $cart
*/
public function removeCart(\Web\AdminBundle\Entity\Cart $cart)
{
$this->cart->removeElement($cart);
}
/**
* Get cart
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getCart()
{
return $this->cart;
}
/**
* Set isSpecial
*
* #param boolean $isSpecial
*
* #return Products
*/
public function setIsSpecial($isSpecial)
{
$this->isSpecial = $isSpecial;
return $this;
}
/**
* Get isSpecial
*
* #return boolean
*/
public function getIsSpecial()
{
return $this->isSpecial;
}
/**
* Set accessoryCategory
*
* #param \Web\AdminBundle\Entity\AccessoryCategory $accessoryCategory
*
* #return Products
*/
public function setAccessoryCategory(\Web\AdminBundle\Entity\AccessoryCategory $accessoryCategory = null)
{
$this->accessoryCategory = $accessoryCategory;
return $this;
}
/**
* Get accessoryCategory
*
* #return \Web\AdminBundle\Entity\AccessoryCategory
*/
public function getAccessoryCategory()
{
return $this->accessoryCategory;
}
/**
* Set oldPrice
*
* #param integer $oldPrice
*
* #return Products
*/
public function setOldPrice($oldPrice)
{
$this->oldPrice = $oldPrice;
return $this;
}
/**
* Get oldPrice
*
* #return integer
*/
public function getOldPrice()
{
return $this->oldPrice;
}
/**
* Set serial
*
* #param string $serial
*
* #return Products
*/
public function setSerial($serial)
{
$this->serial = $serial;
return $this;
}
/**
* Get serial
*
* #return string
*/
public function getSerial()
{
return $this->serial;
}
/**
* Constructor
*/
public function __construct()
{
$this->models = new \Doctrine\Common\Collections\ArrayCollection();
$this->images = new \Doctrine\Common\Collections\ArrayCollection();
$this->cart = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add model
*
* #param \Web\AdminBundle\Entity\Models $model
*
* #return Products
*/
public function addModel(\Web\AdminBundle\Entity\Models $model)
{
$this->models[] = $model;
return $this;
}
/**
* Remove model
*
* #param \Web\AdminBundle\Entity\Models $model
*/
public function removeModel(\Web\AdminBundle\Entity\Models $model)
{
$this->models->removeElement($model);
}
/**
* Get models
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getModels()
{
return $this->models;
}
/**
* Set seller
*
* #param boolean $seller
*
* #return Products
*/
public function setSeller($seller)
{
$this->seller = $seller;
return $this;
}
/**
* Get seller
*
* #return boolean
*/
public function getSeller()
{
return $this->seller;
}
I'm adding new like this:
$em = $this->getDoctrine()->getManager();
$products = new Products();
$article->setTitle('here is the title');
....
$em->persist($products);
$em->flush();
this should set id to like 488 but it's trying to set it to 1. And I don't know why? Might be some cache? But php bin/console cache:clear doesn't change anything.
Doctrine use sequence with the auto strategy and Postgres.
Maybe sequence values has been lost when export/import db.
Identify the sequence used by your ID and try to execute :
ALTER SEQUENCE sequence_name RESTART WITH your_next_free_id;
hi i have got the same problem when i Import my database the probléme s like they say sequence.
But because i have more than 100 table i can't reset the sequence one by one So i Found this query it create for all your table an sql query to update the sequence by the max Id, you have just to copy the result and execute it
SELECT 'SELECT SETVAL(' ||
quote_literal(quote_ident(PGT.schemaname) || '.' || quote_ident(S.relname)) ||
', COALESCE(MAX(' ||quote_ident(C.attname)|| '), 1) ) FROM ' ||
quote_ident(PGT.schemaname)|| '.'||quote_ident(T.relname)|| ';'
FROM pg_class AS S,
pg_depend AS D,
pg_class AS T,
pg_attribute AS C,
pg_tables AS PGT
WHERE S.relkind = 'S'
AND S.oid = D.objid
AND D.refobjid = T.oid
AND D.refobjid = C.attrelid
AND D.refobjsubid = C.attnum
AND T.relname = PGT.tablename
ORDER BY S.relname;
I think as other have suggested its not the issue with symfony or doctrine , instead its postgresql common issue, you can check a solution here
Make sure you are using same version, I am not sure if this behavior differs from version to version.
You can change the current value of the auto increment manually like this :
ALTER TABLE products AUTO_INCREMENT=501;
I know this question has already been asked more than once, but I still can't figure what goes wrong.
I'm currently trying to learn Symfony2 (using version 2.7.4), and I'm getting the following error when I'm trying to reach a page that's supposed to have an image in it :
The target-entity Entity\Image cannot be found in 'OC\PlatformBundle\Entity\Advert#Image'.
Here is my code:
**advert.php**
<?php
namespace OC\PlatformBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity(repositoryClass="OC\PlatformBundle\Entity\AdvertRepository")
*/
class Advert
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\Column(name="published", type="boolean")
*/
private $published = true;
/**
* #ORM\OneToOne(targetEntity="Entity\Image", cascade={"persist"})
*/
private $image;
/**
* #var \DateTime
*
* #ORM\Column(name="date", type="datetime")
*/
private $date;
/**
* #var string
*
* #ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* #var string
*
* #ORM\Column(name="author", type="string", length=255)
*/
private $author;
/**
* #var string
*
* #ORM\Column(name="content", type="text")
*/
private $content;
/**
* Set image
*
* #param \OC\PlatformBundle\Entity\Image $image
*
* #return Advert
*/
public function setImage(\OC\PlatformBundle\Entity\Image $image = null)
{
$this->image = $image;
return $this;
}
/**
* Get Image
*
* #return \OC\PlatformBundle\Entity\Image
*/
public function getImage()
{
return $this->Image;
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
public function __construct()
{
// Par défaut, la date de l'annonce est la date d'aujourd'hui
$this->date = new \Datetime();
}
/**
* Set date
*
* #param \DateTime $date
*
* #return Advert
*/
public function setDate($date)
{
$this->date = $date;
return $this;
}
/**
* Get date
*
* #return \DateTime
*/
public function getDate()
{
return $this->date;
}
/**
* Set title
*
* #param string $title
*
* #return Advert
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* #return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set author
*
* #param string $author
*
* #return Advert
*/
public function setAuthor($author)
{
$this->author = $author;
return $this;
}
/**
* Get author
*
* #return string
*/
public function getAuthor()
{
return $this->author;
}
/**
* Set content
*
* #param string $content
*
* #return Advert
*/
public function setContent($content)
{
$this->content = $content;
return $this;
}
/**
* Get content
*
* #return string
*/
public function getContent()
{
return $this->content;
}
/**
* Set published
*
* #param boolean $published
*
* #return Advert
*/
public function setPublished($published)
{
$this->published = $published;
return $this;
}
/**
* Get published
*
* #return boolean
*/
public function getPublished()
{
return $this->published;
}
}
file Image :
<?php
// src/OC/PlatformBundle/Entity/Image
namespace OC\PlatformBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
*/
class Image
{
/**
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\Column(name="url", type="string", length=255)
*/
private $url;
/**
* #ORM\Column(name="alt", type="string", length=255)
*/
private $alt;
}
I understood that this problem mainly comes from a typo in the call of the entity, but I triple-checked everything, and it seems alright to me... Is there something I didn't see ?
Thank you in advance
You should fix your annotation:
/**
* #ORM\OneToOne(targetEntity="OC\PlatformBundle\Entity\Image", cascade={"persist"})
*/
private $image;
Here are my entities :
/**
* Message_User
*
* #ORM\Table(name="message_user")
* #ORM\Entity
* #ORM\HasLifecycleCallbacks()
*/
class Message_User
{
/**
* #ORM\ManyToOne(targetEntity="Learnpack\UserBundle\Entity\User", inversedBy="mu")
* #ORM\JoinColumn(name="user_id", referencedColumnName="id")
* #ORM\Id
*/
protected $user;
/**
* #ORM\ManyToOne(targetEntity="Learnpack\MessageBundle\Entity\Message", inversedBy="mu")
* #ORM\JoinColumn(name="message_id", referencedColumnName="id")
* #ORM\Id
*/
protected $message;
/**
* #var string $status
*
* #ORM\Column(name="status", type="string", length=45)
*/
private $status;
}
/**
* Message
*
* #ORM\Table(name="message")
* #ORM\Entity
*/
class Message
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="subject", type="string", length=100)
*/
private $subject;
/**
* #var string
*
* #ORM\Column(name="content", type="text")
*/
private $content;
/**
* #var string
*
* #ORM\Column(name="status", type="string", length=45)
*/
private $status;
/**
* #var string
*
* #ORM\Column(name="file", type="string", length=100)
*/
private $file;
/**
* #var \DateTime
*
* #ORM\Column(name="send", type="datetime")
*/
private $send;
/**
* #var \DateTime
*
* #ORM\Column(name="created", type="datetime")
*/
private $created;
/**
* #var \DateTime
*
* #ORM\Column(name="modified", type="datetime")
*/
private $modified;
/**
* #ORM\ManyToOne(targetEntity="Learnpack\UserBundle\Entity\User", inversedBy="user")
* #ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
protected $sender;
Now I would like to make a form with basic message sending. There will be three fields:
Recipient, subject and content.
My problem is that I do not know how to add a field "input" with ajax for the recipient.