Answer the question
In order to leave comments, you need to log in
Why isn't the connection fully working?
There are 2 entities, User and NoticeNotRepeat. Everything is painfully standard, a User can have many Notices, a Notice can only have one User. With such a request.
$user = $em->getRepository(User::class)->findOneBy(['id' => 1]);
$notices = $user->getNoticeNotRepeat();
foreach ($notices as $notice){
dump($notice);
}
dd();
SiteController.php on line 27:
NoticeNotRepeat {#867 ▼
-id: 1
-user_id: 1
-text_notice: "Placeat minus enim dolorum accusamus repellendus. In labore sed ut qui autem eos enim. Et sapiente eius voluptas porro molestiae. Qui ut quasi doloribus veritat ▶"
-sending_at: DateTime @1551401480 {#865 ▶}
-send: false
-user: User {#887 ▼
-id: 1
-email: "[email protected]"
-password: "$argon2i$v=19$m=1024,t=2,p=2$aDFIMU5RN0lySVpZSHZQbw$dVaPxzh3E4zNMYx0igXpqLzQbt2UQpHGQPyW6iEie5Q"
-roles: array:1 [▶]
-username: "sylvester77"
-firstName: "Joel"
-created_at: DateTime @1552071910 {#884 ▶}
-updated_at: DateTime @1552071910 {#885 ▶}
-notice_not_repeat: PersistentCollection {#943 ▶}
-status_notice: false
}
}
$notice = $em->getRepository(NoticeNotRepeat::class)->find(['id' => 1]);
dd($notice);
SiteController.php on line 33:
NoticeNotRepeat {#781 ▼
-id: 1
-user_id: 1
-text_notice: "Placeat minus enim dolorum accusamus repellendus. In labore sed ut qui autem eos enim. Et sapiente eius voluptas porro molestiae. Qui ut quasi doloribus veritat ▶"
-sending_at: DateTime @1551401480 {#779 ▶}
-send: false
-user: User {#844 ▼
+__isInitialized__: false
-id: 1
-email: null
-password: null
-roles: []
-username: null
-firstName: null
-created_at: null
-updated_at: null
-notice_not_repeat: null
-status_notice: false
…2
}
}
/**
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
* @ORM\Table("`user`")
* @UniqueEntity("email")
*/
class User implements UserInterface
{
/**
* @ORM\OneToMany(targetEntity="App\Entity\NoticeNotRepeat", mappedBy="user")
*/
private $notice_not_repeat;
public function __construct()
{
$this->notice_not_repeat = new ArrayCollection();
}
/**
* @return Collection|NoticeNotRepeat[]
*/
public function getNoticeNotRepeat(): Collection
{
return $this->notice_not_repeat;
}
}
class NoticeNotRepeat
{
/**
* @ORM\Column(name="user_id", type="integer", nullable=false, options={"unsigned"=true})
*/
private $user_id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="notice_not_repeat")
* @ORM\JoinColumn(nullable=false)
*/
private $user;
/**
* @return User|null
*/
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
}
Answer the question
In order to leave comments, you need to log in
Dump $notice->getUser(), everything will be there. It's lazy loading doctrine
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question