Всем добрый день. Возникла проблема с расширением entity от model.
Есть entity
<?php
namespace GCS\AdminBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use \GCS\BillingBundle\Model\BillingAccount;
/**
* Account
*
* @ORM\Table(name="gcs_account")
* @ORM\Entity
*/
class Account extends BillingAccount
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* ORM\Column(name="fos_user_id", type="integer", unique=true)
*/
//protected $fos_user_id;
/**
* @ORM\OneToOne(targetEntity="\GCS\KernelBundle\Entity\User")
* @ORM\JoinColumn(name="fos_user_id", referencedColumnName="id")
**/
private $fos_user_id;
/**
* @var string
*
* @ORM\Column(name="username", type="string", length=255, nullable=false)
*/
private $username;
/**
* @var string
*
* @ORM\Column(name="pwd", type="string", length=255, nullable=false)
*/
private $pwd;
/**
* @var string
*
* @ORM\Column(name="email", type="string", length=255, nullable=false)
*/
private $email;
/**
* @var string
*
* @ORM\Column(name="description", type="string", length=255, nullable=false)
*/
private $description;
/**
* @var string
*
* @ORM\Column(name="is_active", type="boolean", options={"default"= 1})
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $isActive;
/**
* @var boolean
*
* @ORM\Column(name="deleted", type="boolean", options={"default"=0})
*/
private $deleted = 0;
/**
* @ORM\OneToMany(targetEntity="\GCS\AdminBundle\Entity\Hotel", mappedBy="account")
*/
protected $hotels;
/**
* @ORM\ManyToOne(targetEntity="\GCS\AdminBundle\Entity\Language")
* @ORM\JoinColumn(name="language_id", referencedColumnName="id", nullable=true)
*/
private $defaultLanguage;
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
$this->hotels = new \Doctrine\Common\Collections\ArrayCollection();
}
наследую её от Model\BillingAccount, код модели ниже
<?php
namespace GCS\BillingBundle\Model;
use Doctrine\ORM\Mapping as ORM;
/**
* Balance
*
* @ORM\Table(name="billing_account")
* @ORM\MappedSuperclass
*/
class BillingAccount
{
public function __construct()
{
$this->balance = 0;
}
/**
* @ORM\Column(name="balance", type="integer", nullable=false)
*/
protected $balance = 0;
/**
* Set balance
*
* @param integer $balance
* @return Account
*/
public function setBalance($balance)
{
$this->balance = $balance;
return $this;
}
/**
* Get balance
*
* @return integer
*/
public function getBalance()
{
return $this->balance;
}
}
Проблема с тем что при extends от model получаю entity с доп поля от модели, но теряю ORM описание полей указанное в модели.
На выходе получается entity с родительскими полями, но без ORM аннотации, и в базе эти поля получается что отсутствуют.
Итог:
<?php
namespace GCS\AdminBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use \GCS\BillingBundle\Model\BillingAccount;
/**
* Account
*
* @ORM\Table(name="gcs_account")
* @ORM\Entity
*/
class Account extends BillingAccount
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* ORM\Column(name="fos_user_id", type="integer", unique=true)
*/
//protected $fos_user_id;
/**
* @ORM\OneToOne(targetEntity="\GCS\KernelBundle\Entity\User")
* @ORM\JoinColumn(name="fos_user_id", referencedColumnName="id")
**/
private $fos_user_id;
/**
* @var string
*
* @ORM\Column(name="username", type="string", length=255, nullable=false)
*/
private $username;
/**
* @var string
*
* @ORM\Column(name="pwd", type="string", length=255, nullable=false)
*/
private $pwd;
/**
* @var string
*
* @ORM\Column(name="email", type="string", length=255, nullable=false)
*/
private $email;
/**
* @var string
*
* @ORM\Column(name="description", type="string", length=255, nullable=false)
*/
private $description;
/**
* @var string
*
* @ORM\Column(name="is_active", type="boolean", options={"default"= 1})
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $isActive;
/**
* @var boolean
*
* @ORM\Column(name="deleted", type="boolean", options={"default"=0})
*/
private $deleted = 0;
/**
* @ORM\OneToMany(targetEntity="\GCS\AdminBundle\Entity\Hotel", mappedBy="account")
*/
protected $hotels;
/**
* @ORM\ManyToOne(targetEntity="\GCS\AdminBundle\Entity\Language")
* @ORM\JoinColumn(name="language_id", referencedColumnName="id", nullable=true)
*/
private $defaultLanguage;
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
$this->hotels = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set fosUserId
*
* @param integer $fos_user_id
* @return Account
*/
public function setFosUserId($fos_user_id)
{
$this->fos_user_id = $fos_user_id;
return $this;
}
/**
* Get fosUserId
*
* @return integer
*/
public function getFosUserId()
{
return $this->fos_user_id;
}
/**
* Set username
*
* @param string $username
* @return Account
*/
public function setUsername($username)
{
$this->username = $username;
return $this;
}
/**
* Get username
*
* @return string
*/
public function getUsername()
{
return $this->username;
}
/**
* Set pwd
*
* @param string $pwd
* @return Account
*/
public function setPwd($pwd)
{
$this->pwd = $pwd;
return $this;
}
/**
* Get pwd
*
* @return string
*/
public function getPwd()
{
return $this->pwd;
}
/**
* Set email
*
* @param string $email
* @return Account
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set description
*
* @param string $description
* @return Account
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set isActive
*
* @param boolean $isActive
* @return Account
*/
public function setIsActive($isActive)
{
$this->isActive = $isActive;
return $this;
}
/**
* Get isActive
*
* @return boolean
*/
public function getIsActive()
{
return $this->isActive;
}
/**
* Set deleted
*
* @param boolean $deleted
* @return Account
*/
public function setDeleted($deleted)
{
$this->deleted = $deleted;
return $this;
}
/**
* Get deleted
*
* @return boolean
*/
public function getDeleted()
{
return $this->deleted;
}
/**
* Add hotels
*
* @param \GCS\AdminBundle\Entity\Hotel $hotels
* @return Account
*/
public function addHotel(\GCS\AdminBundle\Entity\Hotel $hotels)
{
$this->hotels[] = $hotels;
return $this;
}
/**
* Remove hotels
*
* @param \GCS\AdminBundle\Entity\Hotel $hotels
*/
public function removeHotel(\GCS\AdminBundle\Entity\Hotel $hotels)
{
$this->hotels->removeElement($hotels);
}
/**
* Get hotels
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getHotels()
{
return $this->hotels;
}
/**
* Set defaultLanguage
*
* @param \GCS\AdminBundle\Entity\Language $defaultLanguage
* @return Account
*/
public function setDefaultLanguage(\GCS\AdminBundle\Entity\Language $defaultLanguage = null)
{
$this->defaultLanguage = $defaultLanguage;
return $this;
}
/**
* Get defaultLanguage
*
* @return \GCS\AdminBundle\Entity\Language
*/
public function getDefaultLanguage()
{
return $this->defaultLanguage;
}
<b> /**
* @var integer
*/
protected $balance;</b>
/**
* Set balance
*
* @param integer $balance
* @return Account
*/
public function setBalance($balance)
{
$this->balance = $balance;
return $this;
}
/**
* Get balance
*
* @return integer
*/
public function getBalance()
{
return $this->balance;
}
}