Last active
July 26, 2016 14:56
-
-
Save Mohammadtrabelsi/83131f93588708363390a53650006a50 to your computer and use it in GitHub Desktop.
Found entity of type Doctrine\Common\Collections\ArrayCollection on association AppBundle\Entity\Appareil#combustibles, but expecting AppBundle\Entity\Combustible
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace AppBundle\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
use Doctrine\Common\Collections\ArrayCollection; | |
/** | |
* Appareil | |
* | |
* @ORM\Table() | |
* @ORM\Entity | |
*/ | |
class Appareil | |
{ /** | |
* @ORM\ManyToOne(targetEntity="Combustible" , inversedBy="Appareil") | |
* @ORM\JoinColumn(name="combustibles",referencedColumnName="id") | |
*/ | |
private $combustibles; | |
public function addCombustible(Combustible $combustible) | |
{ | |
if (!$this->combustible->contains($combustible)) { | |
$this->combustible->add($combustible); | |
} | |
} | |
public function __toString() { | |
return $this->name; | |
} | |
/** | |
* Set combustibles | |
* | |
* @param \AppBundle\Entity\Combustible $combustibles | |
* @return Appareil | |
*/ | |
public function setCombustibles( $combustibles = null) | |
{ | |
$this->combustibles[] = $combustibles; | |
return $this; | |
} | |
/** | |
* Get combustibles | |
* | |
* @return \AppBundle\Entity\Combustible | |
*/ | |
public function getCombustibles() | |
{ | |
return $this->combustibles; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class AppareilAdmin extends Admin | |
{ | |
protected $baseRouteName = 'AppareilAdmin'; | |
protected $baseRoutePattern = 'AppareilAdmin'; | |
protected function configureFormFields(FormMapper $formMapper) | |
{ | |
$formMapper->add('name', 'text') | |
->add('description', 'textarea') | |
->add('combustibles', 'entity', array('class' => 'AppBundle\Entity\Combustible', 'multiple' => true, 'expanded' => true, 'property' => 'name')) | |
->add('media', 'sonata_media_type', array('provider' => 'sonata.media.provider.image')); | |
} | |
protected function configureDatagridFilters(DatagridMapper $datagridMapper) | |
{ | |
$datagridMapper->add('name')->add('description')->add('combustibles'); | |
} | |
protected function configureListFields(ListMapper $listMapper) | |
{ | |
$listMapper->addIdentifier('name')->add('description')->add('combustibles'); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Combustible | |
* | |
* @ORM\Table() | |
* @ORM\Entity | |
*/ | |
class Combustible | |
{ | |
/** | |
* @ORM\OneToMany(targetEntity="Appareil" , mappedBy="Combustible") | |
*/ | |
private $appareils; | |
/** | |
* Add appareils | |
* | |
* @param \AppBundle\Entity\Appareil $appareils | |
* @return Combustible | |
*/ | |
public function addAppareil(\AppBundle\Entity\Appareil $appareils) | |
{ | |
if (!$this->appareils->contains($appareils)) { | |
$this->appareils->add($appareils); | |
} | |
return $this; | |
} | |
/** | |
* Remove appareils | |
* | |
* @param \AppBundle\Entity\Appareil $appareils | |
*/ | |
public function removeAppareil(\AppBundle\Entity\Appareil $appareils) | |
{ | |
$this->appareils->removeElement($appareils); | |
} | |
/** | |
* Get appareils | |
* | |
* @return \Doctrine\Common\Collections\Collection | |
*/ | |
public function getAppareils() | |
{ | |
return $this->appareils; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adding Many to one relation between tuo entities problem