Answer the question
In order to leave comments, you need to log in
How to get link data correctly in Doctrine using 2 HasMany?
Good afternoon.
The user has several addresses, delivery is carried out to a specific address.
How is it possible to get through the user.deliveries link ?
Or is it only achieved through the repository?
class User
{
#[ORM\OneToMany(mappedBy: "recipient", targetEntity: Address::class, cascade: ["persist"], orphanRemoval: true)]
private Collection|array $addresses;
}
class Address
{
#[Orm\ManyToOne(targetEntity: Recipient::class, inversedBy: 'addresses')]
#[Orm\JoinColumn(name: "user_id", referencedColumnName: "id")]
private User $user;
}
class Delivery {
#[ORM\OneToOne(targetEntity: Address::class)]
#[ORM\JoinColumn(name: "address_id", referencedColumnName: "id")]
private Address $address,
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question