I am developing a simple app in symfony to learn symfony.It has Terms,Example entities.TermExamples is one more entity is one more entitty which is a mapping table between Term and Examples.All is fine but when i try to serialize using JMS serializer ,I get a Reflection exception
These are my entities
Term
/**
* Term
*
* #ORM\Table(name="terms")
* #ORM\Entity
*/
class Term
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="termName", type="string", length=255)
*/
private $termName;
/**
* #var string
*
* #ORM\Column(name="description", type="string", length=2000)
*/
private $description;
/**
* #var string
*
* #ORM\Column(name="mnemonic", type="string", length=2000)
*/
private $mnemonic;
/**
* #var ArrayCollection
*
* #ORM\OneToMany(targetEntity="RelatedTerm",
* mappedBy="term1",cascade={"persist"})
*/
private $relatedTerms;
/**
* #var ArrayCollection
*
* #ORM\OneToMany(targetEntity="TermExample",
* mappedBy="term",cascade={"persist"})
*/
private $termExamples;
public function __construct()
{
$this->relatedTerms = new ArrayCollection();
$this->termExamples = new ArrayCollection();
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Get Related Terms
*/
public function getRelatedTerms()
{
return $this->relatedTerms ;
}
/**
* Add related term
*/
public function addRelatedTerm($relatedTerm)
{
$this->relatedTerms[] = $relatedTerm;
}
/**
* Clear related Terms
*/
public function clearRelatedTerms()
{
$this->relatedTerms->clear();
}
/**
* Remove a related Term
*/
public function removeRelatedTerm($relatedTerm)
{
$this->relatedTerms->removeElement($relatedTerm);
}
/**
* Get Term Examples
*/
public function getTermExamples()
{
return $this->termExamples ;
}
/**
* Add term example
*/
public function addTermExample($termExample)
{
$this->termExamples[] = $termExample;
}
/**
* Clear term examples
*/
public function clearTermExamples()
{
$this->termExamples->clear() ;
}
/**
* Remove a Term Example
*/
public function removeTermExample($termExample)
{
$this->termExamples->removeElement($termExample);
}
/**
* Set termName
*
* #param string $termName
* #return Term
*/
public function setTermName($termName)
{
$this->termName = $termName;
return $this;
}
/**
* Get termName
*
* #return string
*/
public function getTermName()
{
return $this->termName;
}
/**
* Set description
*
* #param string $description
* #return Term
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* #return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set mnemonic
*
* #param string $mnemonic
* #return Term
*/
public function setMnemonic($mnemonic)
{
$this->mnemonic = $mnemonic;
return $this;
}
/**
* Get mnemonic
*
* #return string
*/
public function getMnemonic()
{
return $this->mnemonic;
}
}
Example
/**
* Example
*
* #ORM\Table(name="examples")
* #ORM\Entity
*/
class Example
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="example_sentence", type="string")
*/
private $exampleSentence;
/**
* #var term
*
* #ORM\OneToMany(targetEntity="TermExample",
* mappedBy="example")
*/
private $termExamples;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Get ExampleSentence
*
* #return string
*/
public function getExampleSentence()
{
return $this->exampleSentence;
}
/**
* Set Example sentence
*
* #param string $exampleSentence
*/
public function setExampleSentence($exampleSentence)
{
$this->exampleSentence = $exampleSentence;
return $this;
}
}
?>
TermExample
/**
* TermExample
*
* #ORM\Table(name="term_examples")
* #ORM\Entity
*/
class TermExample
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\ManyToOne(targetEntity="Term",
* inversedBy="termExamples",
* cascade={"persist"})
*/
private $term;
/**
* #ORM\ManyToOne(targetEntity="Example",
* inversedBy="termExamples",
* cascade={"persist"})
*/
private $example;
/**
* #var string
*
* #ORM\Column(name="pos",nullable=true)
*/
private $pos = "NO POS";
//public $exampleSentence;
public function __construct()
{
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Get Term
*
* #return Term
*/
public function getTerm()
{
return $this->term ;
}
/**
* Set Term
* #param Term $term
*
* #return TermExample
*/
public function setTerm($term)
{
$this->term = $term;
$term->addTermExample($this);
}
/**
* Get Example
*
* #return Example
*/
public function getExample()
{
return $this->example ;
}
/**
* Set Example
*
* #return TermExample
*/
public function setExample($example)
{
$this->example = $example;
}
/**
* Get pos
*
* #return string
*/
public function getPos()
{
return $this->pos ;
}
/**
* Set pos
*
* #param string $pos -Parts of speech
*/
public function setPos($pos)
{
$this->pos = $pos;
}
}
When i try to add a term with example sentence,Everything goes fine into the db,but when i try to serialise the term, It shows me an error
"message": "Property Madhuri\\TermsBundle\\Entity\\TermExample::$exampleSentence does not exist",
"class": "ReflectionException",
"trace": [
{
"namespace": "",
"short_class": "",
"class": "",
"type": "",
"function": "",
"file": "/Users/madhuripalagummi/Documents/Dictionary/vendor/jms/metadata/src/Metadata/PropertyMetadata.php",
"line": 75,
"args": []
},
I tried clearing the doctrine cache metadata.But still dint work.
And when i added a field $exampleSentence in TermExample entity,It worked.But why should there be a $exampleSentence in TermExample?
Can anyone please help me?
JMS stores its serialization cache separately to Doctrine so I would try blitzing your cache (i.e. deleting the contents of the cache directory, not just doing a cache:clear command) and trying again. It sounds like the serializer is holding on to old annotations.
Related
First, I'm a french beginner in Symfony4,
Second, I already searched in Symfony Documentation, asked some friends, called my mom..
I'm working on EasyAdminBundle on the form Edit / New Entity.
I have to change the label of my entities but when I do it, my form type is changing.
Here's when picture of my view before editing:
I want to change ' id_equipe' to 'Domicile (home for english )' and id_equipe_equipes to 'exterieur (Visitors)'
So when I tried this :
fields:
- { property: 'id_equipe', label: equipe_domicile}
- { property: 'id_equipe_equipes', label: equipe_extérieur}
The type of the properties is changing to TextArea and I don't know why.
I tried to put a new type like this :
- { property: 'id_equipe', label: equipe_domicile, type: 'choice'}
but my select is blank, I cannot choose anything.
This is what I get:
Thanks you guys
Ps: sorry for ten years old english
So, look, if I understand correctly - id_equipe is a key to external entity. So, this way, to get it worked - you need to use type: 'entity' and also add type_options option, something like that:
- { property: 'id_equipe', label: 'Domicile', type: 'entity', type_options: { class: 'App\Entity\Equipe', multiple: true } }
UPDATE:
So, due to discussion found that the problem was in the property naming. Right to be property: 'idEquipe' not property: 'id_equipe'. So the property names must be same as in the entity, not as the name of the field in the database.
Here's my Matchs entity.
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* Matchs
*
* #ORM\Table(name="matchs", indexes={#ORM\Index(name="MATCHS_EQUIPES1_FK", columns={"ID_EQUIPE_EQUIPES"}), #ORM\Index(name="MATCHS_EQUIPES_FK", columns={"ID_EQUIPE"}), #ORM\Index(name="MATCHS_JOURNEE0_FK", columns={"ID_JOURNEE"})})
* #ORM\Entity
*/
class Matchs
{
/**
* #var int
*
* #ORM\Column(name="ID_MATCHS", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $idMatchs;
/**
* #var \DateTime
*
* #ORM\Column(name="DATE_MATCHS", type="datetime", nullable=false)
*/
private $dateMatchs;
/**
* #var string|null
*
* #ORM\Column(name="RESUME_MATCHS", type="text", length=65535, nullable=true)
*/
private $resumeMatchs;
/**
* #var string|null
*
* #ORM\Column(name="TITRE_MATCH", type="string", length=255, nullable=true)
*/
private $titreMatch;
/**
* #var int
*
* #ORM\Column(name="SCORE_EQUIPE1", type="integer", nullable=false)
*/
private $scoreEquipe1;
/**
* #var int
*
* #ORM\Column(name="SCORE_EQUIPE2", type="integer", nullable=false)
*/
private $scoreEquipe2;
/**
* #var \Equipes
*
* #ORM\ManyToOne(targetEntity="Equipes")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="ID_EQUIPE_EQUIPES", referencedColumnName="ID_EQUIPE")
* })
*/
private $idEquipeEquipes;
/**
* #var \Equipes
*
* #ORM\ManyToOne(targetEntity="Equipes")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="ID_EQUIPE", referencedColumnName="ID_EQUIPE")
* })
*/
private $idEquipe;
/**
* #var \Journee
*
* #ORM\ManyToOne(targetEntity="Journee")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="ID_JOURNEE", referencedColumnName="ID_JOURNEE")
* })
*/
private $idJournee;
/**
* #var \Doctrine\Common\Collections\Collection
*
* #ORM\ManyToMany(targetEntity="JoueursEquipe", inversedBy="idMatchs")
* #ORM\JoinTable(name="jouer",
* joinColumns={
* #ORM\JoinColumn(name="ID_MATCHS", referencedColumnName="ID_MATCHS")
* },
* inverseJoinColumns={
* #ORM\JoinColumn(name="ID_JOUEUR_EQUIPE", referencedColumnName="ID_JOUEUR_EQUIPE")
* }
* )
*/
private $idJoueurEquipe;
/**
* Constructor
*/
public function __construct()
{
$this->idJoueurEquipe = new \Doctrine\Common\Collections\ArrayCollection();
}
public function getIdMatchs()
{
return $this->idMatchs;
}
public function setIdMatchs(int $idMatchs)
{
$this->idMatchs = $idMatchs;
return $this;
}
/**
* Get the value of dateMatchs
*
* #return \DateTime
*/
public function getDateMatchs()
{
return $this->dateMatchs;
}
/**
* Set the value of dateMatchs
*
* #param \DateTime $dateMatchs
*
* #return self
*/
public function setDateMatchs(\DateTime $dateMatchs)
{
$this->dateMatchs = $dateMatchs;
return $this;
}
/**
* Get the value of resumeMatchs
*
* #return string|null
*/
public function getResumeMatchs()
{
return $this->resumeMatchs;
}
/**
* Set the value of resumeMatchs
*
* #param string|null $resumeMatchs
*
* #return self
*/
public function setResumeMatchs($resumeMatchs)
{
$this->resumeMatchs = $resumeMatchs;
return $this;
}
/**
* Get the value of scoreEquipe1
*
* #return int
*/
public function getScoreEquipe1()
{
return $this->scoreEquipe1;
}
/**
* Set the value of scoreEquipe1
*
* #param int $scoreEquipe1
*
* #return self
*/
public function setScoreEquipe1(int $scoreEquipe1)
{
$this->scoreEquipe1 = $scoreEquipe1;
return $this;
}
/**
* Get the value of scoreEquipe2
*
* #return int
*/
public function getScoreEquipe2()
{
return $this->scoreEquipe2;
}
/**
* Set the value of scoreEquipe2
*
* #param int $scoreEquipe2
*
* #return self
*/
public function setScoreEquipe2(int $scoreEquipe2)
{
$this->scoreEquipe2 = $scoreEquipe2;
return $this;
}
/**
* Get the value of idEquipeEquipes
*
* #return \Equipes
*/
public function getIdEquipeEquipes()
{
return $this->idEquipeEquipes;
}
/**
* Set the value of idEquipeEquipes
*
* #param \Equipes $idEquipeEquipes
*
* #return self
*/
public function setIdEquipeEquipes(\Equipes $idEquipeEquipes)
{
$this->idEquipeEquipes = $idEquipeEquipes;
return $this;
}
/**
* Get the value of idEquipe
*
* #return \Equipes
*/
public function getIdEquipe()
{
return $this->idEquipe;
}
/**
* Set the value of idEquipe
*
* #param \Equipes $idEquipe
*
* #return self
*/
public function setIdEquipe(\Equipes $idEquipe)
{
$this->idEquipe = $idEquipe;
return $this;
}
public function __toString()
{
return $this->nomEquipe;
}
/**
* Get the value of idJournee
*
* #return \Journee
*/
public function getIdJournee()
{
return $this->idJournee;
}
/**
* Set the value of idJournee
*
* #param \Journee $idJournee
*
* #return self
*/
public function setIdJournee(\Journee $idJournee)
{
$this->idJournee = $idJournee;
return $this;
}
public function getTitreMatch(): ?string
{
return $this->titreMatch;
}
public function setTitreMatch(string $titreMatch): self
{
$this->titreMatch = $titreMatch;
return $this;
}
/**
* Get the value of idJoueurEquipe
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getIdJoueurEquipe()
{
return $this->idJoueurEquipe;
}
/**
* Set the value of idJoueurEquipe
*
* #param \Doctrine\Common\Collections\Collection $idJoueurEquipe
*
* #return self
*/
public function setIdJoueurEquipe(\Doctrine\Common\Collections\Collection $idJoueurEquipe)
{
$this->idJoueurEquipe = $idJoueurEquipe;
return $this;
}
public function addIdJoueurEquipe(JoueursEquipe $idJoueurEquipe): self
{
if (!$this->idJoueurEquipe->contains($idJoueurEquipe)) {
$this->idJoueurEquipe[] = $idJoueurEquipe;
}
return $this;
}
public function removeIdJoueurEquipe(JoueursEquipe $idJoueurEquipe): self
{
if ($this->idJoueurEquipe->contains($idJoueurEquipe)) {
$this->idJoueurEquipe->removeElement($idJoueurEquipe);
}
return $this;
}
}
I'm making a blog project. So I have an article Class and a Commentaire Blog class.
But I'm having an error when I want to link boths :
[Mapping] FAIL - The entity-class 'AppBundle\Entity\Article' mapping
is invalid:
* The association AppBundle\Entity\Article#commentaires refers to the owning side field AppBundle\Entity\Commentaire_blog#message which is
not defined as association, but as field.
* The association AppBundle\Entity\Article#commentaires refers to the owning side field AppBundle\Entity\Commentaire_blog#message which does
not exist.
[Mapping] FAIL - The entity-class 'AppBundle\Entity\Commentaire_blog'
mapping is invalid:
* The mappings AppBundle\Entity\Commentaire_blog#article and AppBundle\Entity\Article#commentaires are inconsistent with each
other.
I'm a bit lost...
Here are my both Class :
* Article
*
* #ORM\Table(name="article")
* #ORM\Entity(repositoryClass="AppBundle\Repository\ArticleRepository")
*/
class Article
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="Titre", type="text")
*/
private $titre;
/**
* #var string
*
* #ORM\Column(name="article", type="text")
*/
private $article;
/**
* #var \DateTime
*
* #ORM\Column(name="date_article", type="datetime")
*/
private $dateArticle;
/**
* #ORM\OneToMany(targetEntity="Commentaire_blog", mappedBy="messa")
*/
private $commentaires;
public function __construct()
{
$this->commentaires = new ArrayCollection();
}
/**
* #return Collection|Commentaire_blog[]
*/
public function getCommentaires()
{
return $this->commentaires;
}
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set titre
*
* #param string $titre
*
* #return Article
*/
public function setTitre($titre)
{
$this->titre = $titre;
return $this;
}
/**
* Get titre
*
* #return string
*/
public function getTitre()
{
return $this->titre;
}
/**
* Set article
*
* #param string $article
*
* #return Article
*/
public function setArticle($article)
{
$this->article = $article;
return $this;
}
/**
* Get article
*
* #return string
*/
public function getArticle()
{
return $this->article;
}
/**
* Set dateArticle
*
* #param \DateTime $dateArticle
*
* #return Article
*/
public function setDateArticle($dateArticle)
{
$this->dateArticle = $dateArticle;
return $this;
}
/**
* Get dateArticle
*
* #return \DateTime
*/
public function getDateArticle()
{
return $this->dateArticle;
}
And The second :
* Commentaire_blog
*
* #ORM\Table(name="commentaire_blog")
* #ORM\Entity(repositoryClass="AppBundle\Repository \Commentaire_blogRepository")
*/
class Commentaire_blog
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="usernamne", type="string", length=255)
*/
private $usernamne;
/**
* #var string
*
* #ORM\Column(name="message", type="text")
*/
private $message;
/**
* #var bool
*
* #ORM\Column(name="is_visible", type="boolean")
*/
private $isVisible;
/**
* #return mixed
*/
public function getArticle()
{
return $this->article;
}
/**
* #param mixed $article
*/
public function setArticle($article)
{
$this->article = $article;
}
/**
* #ORM\ManyToOne(targetEntity="Article", inversedBy="commentaires")
* #ORM\JoinColumn(nullable=true)
*/
private $article;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set usernamne
*
* #param string $usernamne
*
* #return Commentaire_blog
*/
public function setUsernamne($usernamne)
{
$this->usernamne = $usernamne;
return $this;
}
/**
* Get usernamne
*
* #return string
*/
public function getUsernamne()
{
return $this->usernamne;
}
/**
* Set message
*
* #param string $message
*
* #return Commentaire_blog
*/
public function setMessage($message)
{
$this->message = $message;
return $this;
}
/**
* Get message
*
* #return string
*/
public function getMessage()
{
return $this->message;
}
/**
* Set isVisible
*
* #param boolean $isVisible
*
* #return Commentaire_blog
*/
public function setIsVisible($isVisible)
{
$this->isVisible = $isVisible;
return $this;
}
/**
* Get isVisible
*
* #return bool
*/
public function getIsVisible()
{
return $this->isVisible;
}
}
Any Idea how to make the link correct...
Try this:
Class Article:
/**
* #ORM\OneToMany(targetEntity="Commentaire_blog", mappedBy="article")
*/
private $commentaires;
Class commentaire_blog:
/**
* #ORM\ManyToOne(targetEntity="Article", inversedBy="commentaires")
* #ORM\JoinColumn(nullable=true)
*/
private $article;
Also, consider converting the getCommentaires result to Array:
public function getCommentaires()
{
return $this->commentaires->toArray();
}
To understand more about the owning and inverse side of each relation try reading this: Associations: Owning and Inverse Side.
I have an entity Prototype with a relation many to one with project and I want to override a function in the CRUDController.
Here is the code :
$idPrototype = $this->get('request')->get($this->admin->getIdParameter());
I get the id of the prototype, but I want the parameter 'project' ( the id of the project )
Here is my prototype entity
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Prototype
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="AppBundle\Entity\PrototypeRepository")
*/
class Prototype
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="nom", type="string", length=255)
*/
private $nom;
/**
* #var string
*
* #ORM\Column(name="description", type="string", length=255)
*/
private $description;
/**
* #var \DateTime
*
* #ORM\Column(name="dateCreation", type="date")
*/
private $dateCreation;
private $projet;
public function __construct()
{
$this->dateCreation = new \DateTime("now");
$this->nom = "";
$this->description = " ";
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Get nom
*
* #return string
*/
public function getNom()
{
return $this->nom;
}
public function __toString()
{
return $this->getNom();
}
/**
* Set nom
*
* #param string $nom
* #return Prototype
*/
public function setNom($nom)
{
$this->nom = $nom;
return $this;
}
/**
* Set description
*
* #param string $description
* #return Prototype
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* #return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set dateCreation
*
* #param \DateTime $dateCreation
* #return Prototype
*/
public function setDateCreation($dateCreation)
{
$this->dateCreation = $dateCreation;
return $this;
}
/**
* Get dateCreation
*
* #return \DateTime
*/
public function getDateCreation()
{
return $this->dateCreation;
}
/**
* Set projet
*
* #param \AppBundle\Entity\Projet $projet
* #return Prototype
*/
public function setProjet(\AppBundle\Entity\Projet $projet = null)
{
$this->projet = $projet;
return $this;
}
/**
* Get projet
*
* #return \AppBundle\Entity\Projet
*/
public function getProjet()
{
return $this->projet;
}
}
I've tried to use ModelManager() but I get this error "Attempted to call an undefined method named "getModelManager" of class "AppBundle\Controller\CRUDProtoController". "
I'm new with sonata and symfony and I find difficulties with it.
I have 3 tables: EdiTradingPartner, EdiDocType and EdiTradingPartnerTransactions
src\Matrix\MatrixEdiBundle\Entity\EdiTradingPartner
namespace Matrix\MatrixEdiBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* EdiTradingPartner
*
* #ORM\Table(name="edi_trading_partner")
* #ORM\Entity(repositoryClass="Matrix\MatrixEdiBundle\Repository\EdiTradingPartnerRepository")
*/
class EdiTradingPartner
{
/**
* #var string
*
* #ORM\Column(name="edi_interchange_id", type="string", length=30, nullable=false)
*/
private $ediInterchangeId;
/**
* #var string
*
* #ORM\Column(name="tp_name", type="string", length=30, nullable=false)
*/
private $tpName;
/**
* #var string
*
* #ORM\Column(name="tp_location", type="string", length=50, nullable=false)
*/
private $tpLocation;
/**
* #var integer
*
* #ORM\Column(name="edi_trading_partner_id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $ediTradingPartnerId;
/**
* Set ediInterchangeId
*
* #param string $ediInterchangeId
* #return EdiTradingPartner
*/
public function setEdiInterchangeId($ediInterchangeId)
{
$this->ediInterchangeId = $ediInterchangeId;
return $this;
}
/**
* Get ediInterchangeId
*
* #return string
*/
public function getEdiInterchangeId()
{
return $this->ediInterchangeId;
}
/**
* Set tpName
*
* #param string $tpName
* #return EdiTradingPartner
*/
public function setTpName($tpName)
{
$this->tpName = $tpName;
return $this;
}
/**
* Get tpName
*
* #return string
*/
public function getTpName()
{
return $this->tpName;
}
/**
* Set tpLocation
*
* #param string $tpLocation
* #return EdiTradingPartner
*/
public function setTpLocation($tpLocation)
{
$this->tpLocation = $tpLocation;
return $this;
}
/**
* Get tpLocation
*
* #return string
*/
public function getTpLocation()
{
return $this->tpLocation;
}
/**
* Get ediTradingPartnerId
*
* #return integer
*/
public function getEdiTradingPartnerId()
{
return $this->ediTradingPartnerId;
}
}
src\Matrix\MatrixEdiBundle\Entity\EdiDocType
<?php
namespace Matrix\MatrixEdiBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* EdiDocType
*
* #ORM\Table(name="edi_doc_type")
* #ORM\Entity(repositoryClass="Matrix\MatrixEdiBundle\Repository\EdiDocTypeRepository")
*/
class EdiDocType
{
/**
* #var integer
*
* #ORM\Column(name="doc_type", type="integer", nullable=false)
*/
private $docType;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=50, nullable=false)
*/
private $name;
/**
* #var string
*
* #ORM\Column(name="description", type="string", length=255, nullable=false)
*/
private $description;
/**
* #var string
*
* #ORM\Column(name="direction", type="string", length=10, nullable=false)
*/
private $direction;
/**
* #var integer
*
* #ORM\Column(name="edi_doc_type_id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $ediDocTypeId;
/**
* Set docType
*
* #param integer $docType
* #return EdiDocType
*/
public function setDocType($docType)
{
$this->docType = $docType;
return $this;
}
/**
* Get docType
*
* #return integer
*/
public function getDocType()
{
return $this->docType;
}
/**
* Set name
*
* #param string $name
* #return EdiDocType
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Set description
*
* #param string $description
* #return EdiDocType
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* #return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set direction
*
* #param string $direction
* #return EdiDocType
*/
public function setDirection($direction)
{
$this->direction = $direction;
return $this;
}
/**
* Get direction
*
* #return string
*/
public function getDirection()
{
return $this->direction;
}
/**
* Get ediDocTypeId
*
* #return integer
*/
public function getEdiDocTypeId()
{
return $this->ediDocTypeId;
}
}
src\Matrix\MatrixEdiBundle\Entity\EdiTradingPartnerTransactions
namespace Matrix\MatrixEdiBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* EdiTradingPartnerTransactions
*
* #ORM\Table(name="edi_trading_partner_transactions", indexes={#ORM\Index(name="edi_tp_id", columns={"edi_tp_id", "edi_doc_type_id"}), #ORM\Index(name="edi_transactions_id", columns={"edi_doc_type_id"}), #ORM\Index(name="IDX_F2BE50F7B9C737A1", columns={"edi_tp_id"})})
* #ORM\Entity(repositoryClass="Matrix\MatrixEdiBundle\Repository\EdiTradingPartnerTransactionsRepository")
*/
class EdiTradingPartnerTransactions
{
/**
* #var integer
*
* #ORM\Column(name="edi_tp_transactions_id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $ediTpTransactionsId;
/**
* #var \Matrix\MatrixEdiBundle\Entity\EdiDocType
*
* #ORM\ManyToOne(targetEntity="Matrix\MatrixEdiBundle\Entity\EdiDocType")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="edi_doc_type_id", referencedColumnName="edi_doc_type_id")
* })
*/
private $ediDocType;
/**
* #var \Matrix\MatrixEdiBundle\Entity\EdiTradingPartner
*
* #ORM\ManyToOne(targetEntity="Matrix\MatrixEdiBundle\Entity\EdiTradingPartner")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="edi_tp_id", referencedColumnName="edi_trading_partner_id")
* })
*/
private $ediTp;
/**
* Get ediTpTransactionsId
*
* #return integer
*/
public function getEdiTpTransactionsId()
{
return $this->ediTpTransactionsId;
}
/**
* Set ediDocType
*
* #param \Matrix\MatrixEdiBundle\Entity\EdiDocType $ediDocType
* #return EdiTradingPartnerTransactions
*/
public function setEdiDocType(\Matrix\MatrixEdiBundle\Entity\EdiDocType $ediDocType = null)
{
$this->ediDocType = $ediDocType;
return $this;
}
/**
* Get ediDocType
*
* #return \Matrix\MatrixEdiBundle\Entity\EdiDocType
*/
public function getEdiDocType()
{
return $this->ediDocType;
}
/**
* Set ediTp
*
* #param \Matrix\MatrixEdiBundle\Entity\EdiTradingPartner $ediTp
* #return EdiTradingPartnerTransactions
*/
public function setEdiTp(\Matrix\MatrixEdiBundle\Entity\EdiTradingPartner $ediTp = null)
{
$this->ediTp = $ediTp;
return $this;
}
/**
* Get ediTp
*
* #return \Matrix\MatrixEdiBundle\Entity\EdiTradingPartner
*/
public function getEdiTp()
{
return $this->ediTp;
}
}
I want to insert into EdiTradingPartnerTransactions table yet I really don't know what to do since I've been receiving this error:
Catchable fatal error: Argument 1 passed to
Matrix\MatrixEdiBundle\Entity\EdiTradingPartnerTransactions::setEdiTp()
must be an instance of
Matrix\MatrixEdiBundle\Entity\EdiTradingPartner, string given, called
in
C:\xampp\htdocs\Editracker\src\Matrix\MatrixEdiBundle\Controller\MatrixController.php
on line 474 and defined in
C:\xampp\htdocs\Editracker\src\Matrix\MatrixEdiBundle\Entity\EdiTradingPartnerTransactions.php
on line 85
Here's my function in the controller side:
public function deleteTpTransAction($tpId, $docType, $direction, $tpName) {
$em = $this->getDoctrine()->getManager();
$docTypeId = $em->getRepository('MatrixEdiBundle:EdiDocType')->getId($docType, $direction);
if ($docTypeId != null) {
$result = $em->getRepository('MatrixEdiBundle:EdiTradingPartnerTransactions')->getTpTrans($tpId, $docType, $direction);
if ($result == null) {
$transaction = new EdiTradingPartnerTransactions();
$transaction->setEdiTp($tpId);
$transaction->setEdiDocType($docTypeId);
$em->persist($transaction);
} else {
foreach ($result as $key) {
$id = $key->getEdiTpTransactionsId();
$transaction = $em->getRepository('MatrixEdiBundle:EdiTradingPartnerTransactions')->find($id);
$em->remove($transaction);
}
}
$em->flush();
}
return $this->redirect($this->generateUrl('matrix_edi_tpTrans'));
}
Any help would really be appreciated. Thanks in advanced!
The error here is pretty clear: Doctrine handle, at least for relationships, only objects of the "related" (let's call that way) entity.
When you do
$transaction->setEdiTp($tpId);
$transaction->setEdiDocType($docTypeId);
you're trying to insert ID(s) of related objects. This is an error: although your db expects an integer (foreign key), Doctrine is an abstaction "pillow" between your code and db; it choose to work with objects and not with ids(you can see it pretty clearly into entity classes files)
Solution here is pretty simple:
Fetch from db the entity for setEdiTp and setEdiDocType
Pass them to the functions
In PHP (Symfony):
$ediTp = $em
->getRepository('MatrixEdiBundle:EdiTp')
->findOneById($tpId);
$ediDocType = $em
->getRepository('MatrixEdiBundle:EdiDocType')
->findOneById($docTypeId);
then
$transaction->setEdiTp($ediTp);
$transaction->setEdiDocType($ediDocType);
Your error is because setEdiTp need an instance of EdiTradingPartner.
Your error say string given.
Because $tpId is string.
Verify
Change
$transaction->setEdiTp($tpId);
To
// $transaction->setEdiTp($tpId);
var_dump($tpId);
Normally, $tpId return a string, not a object.
So when you call deleteTpTransAction, $tpId must be an instance of setEdiTp
Changement :
$editp = $em->getRepository('MatrixEdiBundle:EdiTradingPartner')->find($tpId);
and change
$transaction->setEdiTp($tpId);
by
$transaction->setEdiTp($editTp);
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