实体关系疑点
Entity relationship dubts
两个表 Utenti 和 Nuclei 相互关联
Utenti SQL
CREATE TABLE public.utentiweb
(
id bigint NOT NULL,
username character varying(200),
password character varying(128),
idnucleo bigint NOT NULL DEFAULT 0,
)
细胞核SQL
CREATE TABLE public.datinuclei
(
id integer NOT NULL,
idcomune integer NOT NULL,
cognome character varying,
nome character varying,
)
乌腾蒂
/**
* Utentiweb
*
* @ORM\Table(name="utentiweb")
* @ORM\Entity
*/
class Utenti implements UserInterface
{
/**
* @var int
*
* @ORM\Column(name="id", type="bigint", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="SEQUENCE")
* @ORM\SequenceGenerator(sequenceName="utentiweb_id_seq", allocationSize=1, initialValue=1)
*/
private $id;
/**
* @var Nuclei
*
* @ORM\OneToOne(targetEntity="Nuclei", mappedBy="utente")
* @ORM\JoinColumn(name="idnucleo", referencedColumnName="id")
*/
private $nucleo;
细胞核
/**
* Nuclei
*
* @ORM\Table(name="datinuclei")
* @ORM\Entity(repositoryClass="App\Repository\NucleiRepository")
*/
class Nuclei
{
/**
* @var int
*
* @ORM\Id
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\GeneratedValue(strategy="NONE")
*/
private $id;
/**
* @var Utenti
*
* @ORM\OneToOne(targetEntity="Utenti", inversedBy="nucleo")
* @ORM\JoinColumn(name="id", referencedColumnName="id")
*/
private $utente;
从 Utente WORKS 获取 Nucleo
$utente = $this->getDoctrine()->getRepository(Utenti::class)->find(3078);
dump($utente->getNucleo()->getNome());
从 Nucleo 获取 Utente 行不通
$nucleo = $this->getDoctrine()->getRepository(Nuclei::class)->find(5780);
dump($nucleo->getUtente()->getUsername());
错误:
Entity of type 'App\Entity\Utenti' for IDs id(5780) was not found
Nuclei关系标注有问题,不知道怎么解决,nuclei.id应该和utenti.idnucleo有关。尝试了很多组合都没有成功
谢谢
更新 JoinColumn 在 Nuclei 实体上删除
An exception occurred while executing 'SELECT t0.id AS id_1,
t0.tiponucleo AS tiponucleo_2, t0.codicenucleo AS codicenucleo_3,
t0.nome AS nome_4, t0.cognome AS cognome_5, t0.codicefiscale AS
codicefiscale_6, t0.ncomponenti AS ncomponenti_7, t0.indirizzo AS
indirizzo_8, t0.indirizzoutenza AS indirizzoutenza_9, t0.civico AS
civico_10, t0.mail AS mail_11, t0.telefono AS telefono_12,
t0.cellulare AS cellulare_13, t0.utente_id AS utente_id_14,
t0.idcomune AS idcomune_15 FROM datinuclei t0 WHERE t0.id = ?' with
params [5780]:
SQLSTATE[42703]: Undefined column: 7 ERROR: column t0.utente_id does not exist
LINE 1: ...ono AS telefono_12, t0.cellulare AS cellulare_13, t0.utente_...
删除行:
@ORM\JoinColumn(name="id", referencedColumnName="id")
来自classNuclei
字段$utent
两个表 Utenti 和 Nuclei 相互关联
Utenti SQL
CREATE TABLE public.utentiweb
(
id bigint NOT NULL,
username character varying(200),
password character varying(128),
idnucleo bigint NOT NULL DEFAULT 0,
)
细胞核SQL
CREATE TABLE public.datinuclei
(
id integer NOT NULL,
idcomune integer NOT NULL,
cognome character varying,
nome character varying,
)
乌腾蒂
/**
* Utentiweb
*
* @ORM\Table(name="utentiweb")
* @ORM\Entity
*/
class Utenti implements UserInterface
{
/**
* @var int
*
* @ORM\Column(name="id", type="bigint", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="SEQUENCE")
* @ORM\SequenceGenerator(sequenceName="utentiweb_id_seq", allocationSize=1, initialValue=1)
*/
private $id;
/**
* @var Nuclei
*
* @ORM\OneToOne(targetEntity="Nuclei", mappedBy="utente")
* @ORM\JoinColumn(name="idnucleo", referencedColumnName="id")
*/
private $nucleo;
细胞核
/**
* Nuclei
*
* @ORM\Table(name="datinuclei")
* @ORM\Entity(repositoryClass="App\Repository\NucleiRepository")
*/
class Nuclei
{
/**
* @var int
*
* @ORM\Id
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\GeneratedValue(strategy="NONE")
*/
private $id;
/**
* @var Utenti
*
* @ORM\OneToOne(targetEntity="Utenti", inversedBy="nucleo")
* @ORM\JoinColumn(name="id", referencedColumnName="id")
*/
private $utente;
从 Utente WORKS 获取 Nucleo
$utente = $this->getDoctrine()->getRepository(Utenti::class)->find(3078);
dump($utente->getNucleo()->getNome());
从 Nucleo 获取 Utente 行不通
$nucleo = $this->getDoctrine()->getRepository(Nuclei::class)->find(5780);
dump($nucleo->getUtente()->getUsername());
错误:
Entity of type 'App\Entity\Utenti' for IDs id(5780) was not found
Nuclei关系标注有问题,不知道怎么解决,nuclei.id应该和utenti.idnucleo有关。尝试了很多组合都没有成功
谢谢
更新 JoinColumn 在 Nuclei 实体上删除
An exception occurred while executing 'SELECT t0.id AS id_1,
t0.tiponucleo AS tiponucleo_2, t0.codicenucleo AS codicenucleo_3,
t0.nome AS nome_4, t0.cognome AS cognome_5, t0.codicefiscale AS
codicefiscale_6, t0.ncomponenti AS ncomponenti_7, t0.indirizzo AS
indirizzo_8, t0.indirizzoutenza AS indirizzoutenza_9, t0.civico AS
civico_10, t0.mail AS mail_11, t0.telefono AS telefono_12,
t0.cellulare AS cellulare_13, t0.utente_id AS utente_id_14,
t0.idcomune AS idcomune_15 FROM datinuclei t0 WHERE t0.id = ?' with
params [5780]:
SQLSTATE[42703]: Undefined column: 7 ERROR: column t0.utente_id does not exist
LINE 1: ...ono AS telefono_12, t0.cellulare AS cellulare_13, t0.utente_...
删除行:
@ORM\JoinColumn(name="id", referencedColumnName="id")
来自classNuclei
字段$utent