Сущность доктрины наследуется от не сущностного класса

У нас есть простое резюме Node класс следующим образом:

<?php

namespace DataSource\CoreBundle\Model;

/**
* Class Node
* @package DataSource\CoreBundle\Model
*/
abstract class Node
{
protected $id;

/**
* @var Node Parent of current node.
*/
protected $parent = null;

/**
* @var Node[] Children of the current node.
*/
protected $children = array();

/**
* @var string Url of the node.
*/
protected $url;

/**
* @var string Label of the node.
*/
protected $label;

/**
* @return mixed
*/
public function getId()
{
return $this->id;
}

/**
* @return Node[]
*/
public function getChildren()
{
return $this->children;
}

/**
* @param Node[] $children
*/
public function setChildren(array $children)
{
$this->children = $children;
}

/**
* @return bool
*/
public function hasChildren()
{
return count($this->children) > 0;
}

/**
* Add child to the children list.
*
* @param Node $child
*/
public function addChild(Node $child)
{
$this->children[] = $child;
}

/**
* Remove child from children list.
*
* @param Node $child
*/
public function removeChild(Node $child)
{
foreach ($this->children as $key => $_child) {
if ($child->isEqual($_child)) {
unset($this->children[$key]);
}
}
}

/**
* Checks if current node is same as the given node.
*
* @param Node $node
* @return bool
*/
public function isEqual(Node $node)
{
return $node->url == $this->url;
}

/**
* @return string
*/
public function getLabel()
{
return $this->label;
}

/**
* @param string $label
*/
public function setLabel($label)
{
$this->label = $label;
}

/**
* @return Node
*/
public function getParent()
{
return $this->parent;
}

/**
* @param Node $parent
*/
public function setParent($parent)
{
$this->parent = $parent;
}

/**
* @return string
*/
public function getUrl()
{
return $this->url;
}

/**
* @param string $url
*/
public function setUrl($url)
{
$this->url = $url;
}

}

и иметь учение сущности, как показано ниже:

<?php

namespace DataSource\CoreBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* Advertise
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="DataSource\CoreBundle\Repository\AdvertiseRepository")
*/
class Advertise extends \DataSource\CoreBundle\Model\Node
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
}

При обновлении схемы базы данных генерируется только поле id.
Как можно наследовать Node свойства модели и есть ли они в схеме базы данных?

1

Решение

Если вы хотите наследовать свойства абстрактного класса, я бы хотел либо сделать его MappedSuperClass — в противном случае вы можете сделать класс сущностью и использовать наследование одной таблицы или что-то подобное.

Пример и т. Д. Можно найти здесь: http://doctrine-orm.readthedocs.org/en/latest/reference/inheritance-mapping.html

Надеюсь это поможет!

0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector