tôi sẽ simplifly mã của tôi, tôi có te tiếp theo:Symfony ManyToOne mối quan hệ getter lợi nhuận trống đối tượng
Doctor thực thể:
use ...\...\Entity\Paciente;
class Doctor extends Usuario {
public function __construct() {
...
$this->pacientes = new ArrayCollection();
...
}
/**
* Número de colegiado - numColegiado
*
* @var string
*
* @ORM\Column(name="numColegiado", type="string", length=255, unique=true)
*/
protected $numColegiado;
/**
* @ORM\OneToMany(targetEntity="Paciente", mappedBy="doctor")
* @var \Doctrine\Common\Collections\ArrayCollection
*/
private $pacientes;
...
}
Paciente thực thể:
use \...\...\Entity\Doctor;
...
class Paciente extends Usuario {
}
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Doctor", inversedBy="pacientes")
* @ORM\JoinColumn(name="doctorNum", referencedColumnName="numColegiado", nullable=TRUE)
*
* @var type
*/
protected $doctor;
...
/**
* Set doctor
*
* @param Doctor $doctor
* @return Paciente
*/
public function setDoctor(Doctor $doctor = null)
{
$this->doctor = $doctor;
return $this;
}
/**
* Get doctor
*
* @return Doctor
*/
public function getDoctor()
{
return $this->doctor;
}
}
Ok, vấn đề này là khi tôi thực thi mã đó (tất nhiên có mối quan hệ được tạo và đối tượng này tồn tại trong cơ sở dữ liệu):
\Doctrine\Common\Util\Debug::dump($paciente->getDoctor());
Nó in rằng sau:
object(stdClass)#804 (28) { ["__CLASS__"]=> string(34) "Knoid\CorcheckBundle\Entity\Doctor" ["__IS_PROXY__"]=> bool(true) ["__PROXY_INITIALIZED__"]=> bool(false) ["id"]=> NULL ["numColegiado"]=> NULL ["pacientes"]=> NULL ["nombre"]=> NULL ["apellidos"]=> NULL ["dni"]=> NULL ["tipo"]=> NULL ["username"]=> NULL ["usernameCanonical"]=> NULL ["email"]=> NULL ["emailCanonical"]=> NULL ["enabled"]=> NULL ["salt"]=> NULL ["password"]=> NULL ["plainPassword"]=> NULL ["lastLogin"]=> NULL ["confirmationToken"]=> NULL ["passwordRequestedAt"]=> NULL ["groups"]=> NULL ["locked"]=> NULL ["expired"]=> NULL ["expiresAt"]=> NULL ["roles"]=> NULL ["credentialsExpired"]=> NULL ["credentialsExpireAt"]=> NULL }
Như bạn có thể thấy, tất cả các atributes của đối tượng "bác sĩ" là null, đối tượng tồn tại nhưng nó trống rỗng, trong DB của tôi đối tượng này tồn tại và nó isn' t trống.
Bất kỳ ý tưởng nào về những gì đang xảy ra?
Bằng cách nào đó nó tương quan với điều đó. Bây giờ tôi recived này ngoại lệ: "[1/2] ErrorException: Thông báo: Undefined chỉ số: id trong /var/www/vhosts/default/htdocs/Symfony/app/cache/dev/doctrine/orm/Proxies/__CG__KnoidCorcheckBundleEntityDoctor.php dòng 48 "nhưng chỉ khi tôi cố gắng lấy id của bác sĩ. –
Tôi cho rằng bạn đã xác định/tạo ra một getter cho id? –
Có, "hàm getId công cộng() { trả về $ this-> id; }" trong lớp thực thể bác sĩ –