T
T
tukreb2020-03-09 15:02:11
Doctrine ORM
tukreb, 2020-03-09 15:02:11

How to disable inheritance in Doctrine?

How can I disable inheritance in doctrine? That is, so that doctrina does not check mapping and works with these classes as with ordinary classes without extends.

I only need inheritance in this situation to inherit some methods that I do not want to be called directly from the parent.

UPD:
I tried using the InheritanceType("JOINED") approach, but it throws me an error
SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
which I can't trace.

Here is an example of simplified classes.

/**
 * Parent
 * @ORM\Table(blablabla)
 * @ORM\Entity
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorColumn(name="discr", type="string")
 * @ORM\DiscriminatorMap({
 *     "parent" = "App\Model\Parent\Parent",
 *     "children" = "App\Model\Children\Children"
 * })
 */
class Parent
{
  /**
     * @var Id
     *
     * @ORM\Column(name="id_parent", type="parent_id", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="NONE")
     */
    protected $id;
  
  //другие поля.
  
  protected function __construct(Id $id, ........)
  {
    ///...... init
  }
}


/**
 * Children
 *
 * @ORM\Table(blablabla)
 * @ORM\Entity
 */
class Children extends Parent
{
  /**
     * @var Parent
     *
     * @ORM\OneToOne(targetEntity="App\Model\Parent\Parent", cascade={"persist", "remove"})
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="id_parent", referencedColumnName="id_parent", onDelete="CASCADE")
     * })
     */
    private $item;
  
  /**
     * @var SomeClassForChilder|null
     *
     * @ORM\OneToOne(targetEntity="App\Model\SomeClassForChilder\SomeClassForChilder",
     *     mappedBy="children", cascade={"persist"})
     */
    private $someClassForChilder;
  
  //другие поля.
  
  public function __construct(Id $id, ........)
  {
    parent::__construct(Id $id, ....);
    $this->someClassForChilder = new SomeClassForChilder($this)
    ///...... init
  }
}


/**
 * SomeClassForChilder
 *
 * @ORM\Table(blablabla)
 * @ORM\Entity
 */
class SomeClassForChilder
{
  /**
     * @var Children
     *
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="NONE")
     * @ORM\OneToOne(targetEntity="App\Model\Children\Children",
     *     inversedBy="someClassForChilder", cascade={"persist", "remove"})
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="id_parent", referencedColumnName="id_parent", onDelete="CASCADE")
     * })
     */
    private $children;
  
  public function __construct(Children $children)
  {
    ///...... init
  }
  
}


Next, save to the database

$children = new Children($id, ....);
persist(children )
flash...


And we get the error
SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

Without inheritance, there are no problems.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tukreb, 2020-03-09
@tukreb

In class Parent
protected $id;
renamed to
protected $id_parent;
Funny mistake. And how I was supposed to diagnose it without the poke method is not clear, but oh well ..

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question