Witam ;)
Mam dwie Encje:
-Kierowcy
class Kierowcy
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=50)
*/
private $Imie;
/**
* @ORM\Column(type="string", length=50)
*/
private $Nazwisko;
/**
* @ORM\Column(type="integer")
*/
private $Wiek;
/**
* @ORM\OneToMany(targetEntity="Samochody", mappedBy="Ownerid")
*/
private $Autaid;
public function __construct()
{
$this->Autaid = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getImie(): ?string
{
return $this->Imie;
}
public function setImie(string $Imie): self
{
$this->Imie = $Imie;
return $this;
}
public function getNazwisko(): ?string
{
return $this->Nazwisko;
}
public function setNazwisko(string $Nazwisko): self
{
$this->Nazwisko = $Nazwisko;
return $this;
}
public function getWiek(): ?int
{
return $this->Wiek;
}
public function setWiek(int $Wiek): self
{
$this->Wiek = $Wiek;
return $this;
}
/**
* @return Collection|Samochody[]
*/
public function getAutaid(): Collection
{
return $this->Autaid;
}
public function addAutaid(Samochody $autaid): self
{
if (!$this->Autaid->contains($autaid)) {
$this->Autaid[] = $autaid;
$autaid->setOwnerid($this);
}
return $this;
}
public function removeAutaid(Samochody $autaid): self
{
if ($this->Autaid->contains($autaid)) {
$this->Autaid->removeElement($autaid);
// set the owning side to null (unless already changed)
if ($autaid->getOwnerid() === $this) {
$autaid->setOwnerid(null);
}
}
return $this;
}
}
-Samochody
class Samochody
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=50)
*/
private $Marka;
/**
* @ORM\Column(type="string", length=50)
*/
private $Model;
/**
* @ORM\Column(type="date")
*/
private $Produkcja;
/**
* @ORM\Column(type="string", length=100)
*/
private $Komentarz;
/**
* @ORM\Column(type="integer")
*/
private $Usterka;
/**
* @ORM\Column(type="integer", nullable=true)
*/
/**
* @ORM\ManyToOne(targetEntity="Kierowcy", inversedBy="Autaid")
*/
private $Ownerid;
public function getId(): ?int
{
return $this->id;
}
public function getMarka(): ?string
{
return $this->Marka;
}
public function setMarka(string $Marka): self
{
$this->Marka = $Marka;
return $this;
}
public function getModel(): ?string
{
return $this->Model;
}
public function setModel(string $Model): self
{
$this->Model = $Model;
return $this;
}
public function getProdukcja(): ?\DateTimeInterface
{
return $this->Produkcja;
}
public function setProdukcja(\DateTimeInterface $Produkcja): self
{
$this->Produkcja = $Produkcja;
return $this;
}
public function getKomentarz(): ?string
{
return $this->Komentarz;
}
public function setKomentarz(?string $Komentarz): self
{
$this->Komentarz = $Komentarz;
return $this;
}
public function getUsterka(): ?int
{
return $this->Usterka;
}
public function setUsterka(int $Usterka): self
{
$this->Usterka = $Usterka;
return $this;
}
public function getOwnerid(): ?int
{
return $this->Ownerid;
}
public function setOwnerid(?int $Ownerid): self
{
$this->Ownerid = $Ownerid;
return $this;
}
}
Relacja Samochody.php
/**
* @ORM\ManyToOne(targetEntity="Kierowcy", inversedBy="Autaid")
*/
private $Ownerid;
Relacja Kierowcy.php
/**
* @ORM\OneToMany(targetEntity="Samochody", mappedBy="Ownerid")
*/
private $Autaid;
Tworzę zapytanie za pomocą metody createquerybuilder
public function queryOwner5()
{
return $this->createQueryBuilder('k')
->select('k.Imie','k.Nazwisko','k.Wiek','s.Marka','s.Model')
->innerJoin('App\Entity\Samochody','s','WITH','k.id=s')
->getQuery()
->getResult()
;
}
Oto tabele:
Jak robie zapytanie w sqlu:
SELECT kierowcy.Imie,kierowcy.Nazwisko,kierowcy.Wiek,samochody.Marka,samochody.Model FROM kierowcy INNER JOIN samochody ON kierowcy.id=samochody.Ownerid;
to wynik jest prawidłowy:
jak zrobie createquerybuilder:
public function queryOwner5()
{
return $this->createQueryBuilder('k')
->select('k.Imie','k.Nazwisko','k.Wiek','s.Marka','s.Model')
->innerJoin('App\Entity\Samochody','s','WITH','k.id=s')
->getQuery()
->getResult()
;
}
To wychodzi wynik, ale niepoprawny:
Gdzie może znajdować się błąd??
Z góry dzięki ;)