Answer the question
In order to leave comments, you need to log in
How to administer Doctrine ORM Class Table Inheritance via SonataAdminBundle (Symfony)?
Good afternoon!
I have a Doctrine entity Foo that is related One-To-One to an AbstractBar entity:
/**
* @ORM\Table(name="foo")
* @ORM\Entity
*/
class Foo
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var AbstractBar
*
* @ORM\OneToOne(targetEntity="AbstractBar", cascade={"persist"})
* @ORM\JoinColumn(name="bar_id", referencedColumnName="id")
*/
private $bar;
}
/**
* @ORM\Table(name="bar")
* @ORM\Entity
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="bar_type", type="string")
* @ORM\DiscriminatorMap({"one" = "BarOne", "two" = "BarTwo"})
*/
abstract class AbstractBar
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
}
/**
* @ORM\Table(name="bar_one")
* @ORM\Entity
*/
class BarOne extends AbstractBar
{
// свойства класса BarOne
}
/**
* @ORM\Table(name="bar_two")
* @ORM\Entity
*/
class BarTwo extends AbstractBar
{
// свойства класса BarTwo
}
class FooAdmin extends AbstractAdmin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('bar', AdminType::class, array(), array(
'admin_code' => 'key.of.bar_one.admin.service'
))
;
}
}
key.of.bar_one.admin.service:
class: MyBundle\Admin\BarAdmin
arguments: [~, MyBundle\Entity\BarOne, ~]
tags:
- name: sonata.admin
manager_type: orm
show_in_dashboard: false
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question