Есть 2 сущности. Между ними связь Serviceviewgrouptable:Serviceviewtable = Один:Многие
Сущность Serviceviewgrouptable:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Serviceviewgrouptable
*
* @ORM\Table(name="ServiceViewGroupTable")
* @ORM\Entity
*/
class Serviceviewgrouptable
{
/**
* @var string
*
* @ORM\Column(name="ServiceGroupID", type="string", length=4, nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $servicegroupid;
/**
* @var string
*
* @ORM\Column(name="ServiceGroupName", type="string", length=200, nullable=false)
*/
private $servicegroupname;
/**
* Get servicegroupid
*
* @return string
*/
public function getServicegroupid()
{
return $this->servicegroupid;
}
/**
* Set servicegroupname
*
* @param string $servicegroupname
*
* @return Serviceviewgrouptable
*/
public function setServicegroupname($servicegroupname)
{
$this->servicegroupname = $servicegroupname;
return $this;
}
/**
* Get servicegroupname
*
* @return string
*/
public function getServicegroupname()
{
return $this->servicegroupname;
}
}
Сущность Serviceviewtable:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Serviceviewtable
*
* @ORM\Table(name="ServiceViewTable", indexes={@ORM\Index(name="IDX_D60FFB86795E9A44", columns={"ServiceGroupKod"}), @ORM\Index(name="IDX_D60FFB8664257B57", columns={"ServiceMeasureKod"})})
* @ORM\Entity
*/
class Serviceviewtable
{
/**
* @var string
*
* @ORM\Column(name="ServiceID", type="string", length=10, nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $serviceid;
/**
* @var string
*
* @ORM\Column(name="ServiceName", type="string", length=200, nullable=false)
*/
private $servicename;
/**
* @var string
*
* @ORM\Column(name="ServiсeDefaultPrice", type="decimal", precision=18, scale=2, nullable=true)
*/
private $servicedefaultprice;
/**
* @var string
*
* @ORM\Column(name="ServiсeDescription", type="string", length=2000, nullable=true)
*/
private $servicedescription;
/**
* @var \AppBundle\Entity\Serviceviewgrouptable
*
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Serviceviewgrouptable")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="ServiceGroupKod", referencedColumnName="ServiceGroupID")
* })
*/
private $servicegroupkod;
/**
* Get serviceid
*
* @return string
*/
public function getServiceid()
{
return $this->serviceid;
}
/**
* Set servicename
*
* @param string $servicename
*
* @return Serviceviewtable
*/
public function setServicename($servicename)
{
$this->servicename = $servicename;
return $this;
}
/**
* Get servicename
*
* @return string
*/
public function getServicename()
{
return $this->servicename;
}
/**
* Set servicedefaultprice
*
* @param string $servicedefaultprice
*
* @return Serviceviewtable
*/
public function setServicedefaultprice($servicedefaultprice)
{
$this->servicedefaultprice = $servicedefaultprice;
return $this;
}
/**
* Get servicedefaultprice
*
* @return string
*/
public function getServicedefaultprice()
{
return $this->servicedefaultprice;
}
/**
* Set servicedescription
*
* @param string $servicedescription
*
* @return Serviceviewtable
*/
public function setServicedescription($servicedescription)
{
$this->servicedescription = $servicedescription;
return $this;
}
/**
* Get servicedescription
*
* @return string
*/
public function getServicedescription()
{
return $this->servicedescription;
}
/**
* Set servicegroupkod
*
* @param \AppBundle\Entity\Serviceviewgrouptable $servicegroupkod
*
* @return Serviceviewtable
*/
public function setServicegroupkod(\AppBundle\Entity\Serviceviewgrouptable $servicegroupkod = null)
{
$this->servicegroupkod = $servicegroupkod;
return $this;
}
/**
* Get servicegroupkod
*
* @return \AppBundle\Entity\Serviceviewgrouptable
*/
public function getServicegroupkod()
{
return $this->servicegroupkod;
}
}
Создаю форму:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('serviceid', HiddenType::class)
->add('servicename', TextType::class, array(
'label' => 'Наименование',
'attr' => array('class' => 'form-control'),
))
->add('servicedefaultprice', TextType::class, array(
'label' => 'Стоимость',
'attr' => array('class' => 'form-control count')
))
->add('servicedescription', TextareaType::class, array(
'label' => 'Описание',
'attr' => array('class' => 'form-control')
))
->add('submit', SubmitType::class, array(
'label' => 'Сохранить',
'attr' => array('class' => 'btn btn-danger')
))
->add('servicegroupkod');
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'AppBundle\Entity\Serviceviewtable'
));
}
Но при отображении формы вылетает ошибка:
Catchable Fatal Error: Object of class AppBundle\Entity\Serviceviewgrouptable could not be converted to string
Каким образом можно отобразить данные из поля связанной таблицы ?