0
我遇到了麻煩,我需要您的幫助。現在,我創建兩個實體:兩個實體之間的關係
- 合作伙伴
- PartnerMedia
合夥實體包含有關我的合作伙伴和其他實體的所有信息,與合作伙伴和索納塔媒體實體關係。
有哪些包含我的合夥人實體:
<?php
namespace AppBundle\Entity;
use AppBundle\Entity\CMS\Block;
use AppBundle\Entity\SuperClass\SortableTranslatableEntity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Sonata\MediaBundle\Model\Media;
use Doctrine\Common\Collections\ArrayCollection;
use Sonata\TranslationBundle\Model\Gedmo\TranslatableInterface;
/**
* Partner.
*
* @ORM\Table("partner")
* @ORM\Entity
*/
class Partner extends SortableTranslatableEntity implements TranslatableInterface
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="libelle", type="string", length=60)
* @Gedmo\Translatable
*/
private $libelle;
/**
* @var string
*
* @ORM\Column(name="mea", type="boolean")
*/
private $mea;
/**
* @ORM\OneToMany(targetEntity="\AppBundle\Entity\Media\PartnerMedia", mappedBy="partner", cascade={"persist"}, orphanRemoval=true)
* @ORM\OrderBy({"position" = "ASC"})
*/
private $medias;
/**
* @ORM\Column(type="string", name="url", nullable=true)
* @Gedmo\Translatable
*/
private $url;
/**
* @ORM\ManyToOne(targetEntity="\AppBundle\Entity\CMS\Block", inversedBy="block")
*/
private $block;
public function __construct()
{
$this->medias = new ArrayCollection();
}
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
public function getContextName()
{
return 'partner';
}
public function __toString()
{
return $this->getId() ? (string) $this->getLibelle() : '-';
}
public function firstPhoto()
{
if ($this->getMedias() && $this->getMedias()->count()) {
return $this->getMedias()->first()->getMedia();
}
}
public function getId()
{
return $this->id;
}
public function getLibelle()
{
return $this->libelle;
}
/**
* Add medias.
*
* @param PartnerMedia $media
*
* @return PartnerMedia
*/
public function addMedias(PartnerMedia $media)
{
$media->setPartner($this);
$this->medias[] = $media;
return $this;
}
/**
* Remove medias.
*
* @param PartnerMedia $media
*/
public function removeMedia(PartnerMedia $media)
{
$this->medias->removeElement($media);
}
public function getMedias()
{
return $this->medias;
}
public function getUrl()
{
return $this->url;
}
/**
* Get page.
*
* @return \AppBundle\Entity\CMS\Block
*/
public function getBlock()
{
return $this->block;
}
public function setId($id)
{
$this->id = $id;
}
public function setLibelle($libelle)
{
$this->libelle = $libelle;
}
public function setUrl($url)
{
$this->url = $url;
}
/**
* Set page.
*
* @param \AppBundle\Entity\CMS\Block $block
* @return Partner
*/
public function setBlock(Block $block = null)
{
$this->block = $block;
return $this;
}
/**
* Set mea
*
* @param boolean $mea
* @return Partner
*/
public function setMea($mea)
{
$this->mea = $mea;
return $this;
}
/**
* Get mea
*
* @return boolean
*/
public function getMea()
{
return $this->mea;
}
/**
* @param mixed $medias
*/
public function setMedias($medias)
{
$this->medias = $medias;
}
}
,哪些包含PartnerMedia實體:
<?php
/**
* PartnerMedia
*
* @ORM\Table()
* @ORM\Entity
*/
class PartnerMedia extends SortableEntity
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="\Application\Sonata\MediaBundle\Entity\Media")
*/
private $medias;
/**
* @ORM\ManyToOne(targetEntity="\AppBundle\Entity\Partner", inversedBy="partner")
*
* @Gedmo\SortableGroup
*/
private $partner;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set medias
*
* @param Media $medias
* @return PartnerMedia
*/
public function setMedias(Media $medias = null)
{
$this->medias = $medias;
return $this;
}
/**
* Get medias
*
* @return Media
*/
public function getMedias()
{
return $this->medias;
}
/**
* Set Partner
*
* @param Partner $partner
* @return PartnerMedia
*/
public function setPartner(Partner $partner = null)
{
$this->partner = $partner;
return $this;
}
/**
* Get Partner
*
* @return Partner
*/
public function getPartner()
{
return $this->partner;
}
public function getContextName()
{
return 'partner_media';
}
public function __construct()
{
$this->medias = new ArrayCollection();
}
}
現在,當我試圖創建一個新的合作伙伴,我收到異常:
當前字段
medias
未鏈接到管理員。請創建一個針對目標實體:AppBundle\Entity\Media\PartnerMedia
我需要你們的幫助,請和感謝