I am asking something about the result of the request. I don't have the same result when I use MySql and Doctrine ... I have a field that changes when it is executed (package -> id).
My query in mysql:
"SELECT *
FROM packages_dates_prices
INNER JOIN packages
ON packages_dates_prices.id = packages.id
AND packages_dates_prices.package ='.$id.'"
My query in the repository and in DQL:
"SELECT a
FROM BackBundle:PackagesDatesPrices a
INNER JOIN BackBundle:Packages b
WHERE a.id = b.id
AND a.package = :id
"
Query on the debug toolbar:
SELECT
e0_.id AS id0,
e0_.date_start AS date_start1,
e0_.date_end AS date_end2,
e0_.price AS price3,
e0_.id AS id4
FROM
packages_dates_prices e0_
INNER JOIN packages e1_ ON (
e0_.id = e1_.id
AND e0_.id = ?
)
Parameters: [1]
Entity Packages:
<?php
namespace Back\Bundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
class Packages
{
private $id;
private $title;
private $description;
private $details;
private $essential;
private $indices;
private $mysterious;
private $products;
private $attachment;
private $metaKeywords;
private $metaDescription;
private $createdAt;
private $agent;
private $place;
private $theme;
private $updatedAt;
private $isActive;
private $isHome;
private $link;
private $orderHome;
private $slug;
private $isOuting;
private $isWeekend;
private $isWedding;
private $isPresent;
private $isCompany;
private $isSolo;
private $isCouple;
private $isFriends;
private $isFamily;
private $datesPrices;
public function __construct()
{
$this->createdAt = new \Datetime();
$this->datesPrices = new \Doctrine\Common\Collections\ArrayCollection();
}
public function getPeople()
{
return sprintf("%s %s", $this->getIsSolo(), $this->getIsCouple(), $this->getIsFriends(), $this->getIsFamily());
}
public function __toString()
{
if ($this->getId())
return "Packages n° ".$this->getId();
return "Nouveau Package";
}
public function getId()
{
return $this->id;
}
public function setTitle($title)
{
$this->title = $title;
return $this;
}
public function getTitle()
{
return $this->title;
}
public function setDescription($description)
{
$this->description = $description;
return $this;
}
public function getDescription()
{
return $this->description;
}
public function setDetails($details)
{
$this->details = $details;
return $this;
}
public function getDetails()
{
return $this->details;
}
public function setEssential($essential)
{
$this->essential = $essential;
return $this;
}
public function getEssential()
{
return $this->essential;
}
public function setIndices($indices)
{
$this->indices = $indices;
return $this;
}
public function getIndices()
{
return $this->indices;
}
public function setMysterious($mysterious)
{
$this->mysterious = $mysterious;
return $this;
}
public function getMysterious()
{
return $this->mysterious;
}
public function setProducts($products)
{
$this->products = $products;
return $this;
}
public function getProducts()
{
return $this->products;
}
public function setAttachment($attachment)
{
$this->attachment = $attachment;
return $this;
}
public function getAttachment()
{
return $this->attachment;
}
public function setMetaKeywords($metaKeywords)
{
$this->metaKeywords = $metaKeywords;
return $this;
}
public function getMetaKeywords()
{
return $this->metaKeywords;
}
public function setMetaDescription($metaDescription)
{
$this->metaDescription = $metaDescription;
return $this;
}
public function getMetaDescription()
{
return $this->metaDescription;
}
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
public function getCreatedAt()
{
return $this->createdAt;
}
public function setAgent($agent)
{
$this->agent = $agent;
return $this;
}
public function getAgent()
{
return $this->agent;
}
public function setPlace($place)
{
$this->place = $place;
return $this;
}
public function getPlace()
{
return $this->place;
}
public function setTheme($theme)
{
$this->theme = $theme;
return $this;
}
public function getTheme()
{
return $this->theme;
}
public function setUpdatedAt($updatedAt)
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getUpdatedAt()
{
return $this->updatedAt;
}
public function setIsActive($isActive)
{
$this->isActive = $isActive;
return $this;
}
public function getIsActive()
{
return $this->isActive;
}
public function setIsHome($isHome)
{
$this->isHome = $isHome;
return $this;
}
public function getIsHome()
{
return $this->isHome;
}
public function setLink($link)
{
$this->link = $link;
return $this;
}
public function getLink()
{
return $this->link;
}
public function setOrderHome($orderHome)
{
$this->orderHome = $orderHome;
return $this;
}
public function getOrderHome()
{
return $this->orderHome;
}
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
public function getSlug()
{
return $this->slug;
}
public function setIsOuting($isOuting)
{
$this->isOuting = $isOuting;
return $this;
}
public function getIsOuting()
{
return $this->isOuting;
}
public function setIsWeekend($isWeekend)
{
$this->isWeekend = $isWeekend;
return $this;
}
public function getIsWeekend()
{
return $this->isWeekend;
}
public function setIsWedding($isWedding)
{
$this->isWedding = $isWedding;
return $this;
}
public function getIsWedding()
{
return $this->isWedding;
}
public function setIsPresent($isPresent)
{
$this->isPresent = $isPresent;
return $this;
}
public function getIsPresent()
{
return $this->isPresent;
}
public function setIsCompany($isCompany)
{
$this->isCompany = $isCompany;
return $this;
}
public function getIsCompany()
{
return $this->isCompany;
}
public function setIsSolo($isSolo)
{
$this->isSolo = $isSolo;
return $this;
}
public function getIsSolo()
{
return $this->isSolo;
}
public function setIsCouple($isCouple)
{
$this->isCouple = $isCouple;
return $this;
}
public function getIsCouple()
{
return $this->isCouple;
}
public function setIsFriends($isFriends)
{
$this->isFriends = $isFriends;
return $this;
}
public function getIsFriends()
{
return $this->isFriends;
}
public function setIsFamily($isFamily)
{
$this->isFamily = $isFamily;
return $this;
}
public function getIsFamily()
{
return $this->isFamily;
}
public function addDatesPrice(\Back\Bundle\Entity\PackagesDatesPrices $datesPrices)
{
$this->datesPrices[] = $datesPrices;
$datesPrices->setPackage($this);
return $this;
}
public function removeDatesPrice(\Back\Bundle\Entity\PackagesDatesPrices $datesPrices)
{
$this->datesPrices->removeElement($datesPrices);
}
public function getDatesPrices()
{
return $this->datesPrices;
}
}
PackagesDatesPrices:
<?php
namespace Back\Bundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
class PackagesDatesPrices
{
private $id;
private $package;
private $dateStart;
private $dateEnd;
private $price;
public function __construct() {
$this->children = new \Doctrine\Common\Collections\ArrayCollection();
}
public function getId()
{
return $this->id;
}
public function setDateStart($dateStart)
{
$this->dateStart = $dateStart;
return $this;
}
public function getDateStart()
{
return $this->dateStart;
}
public function setDateEnd($dateEnd)
{
$this->dateEnd = $dateEnd;
return $this;
}
public function getDateEnd()
{
return $this->dateEnd;
}
public function setPrice($price)
{
$this->price = $price;
return $this;
}
public function getPrice()
{
return $this->price;
}
public function setPackage(\Back\Bundle\Entity\Packages $package = null)
{
$this->package = $package;
return $this;
}
public function getPackage()
{
return $this->package;
}
}
PackagesDatesPricesRepository.php:
<?php
namespace Back\Bundle\Entity;
use Doctrine\ORM\EntityRepository;
class PackagesDatesPricesRepository extends EntityRepository
{
public function getTest($id)
{
$req=$this->getEntityManager()->createQuery
(
"SELECT a
FROM BackBundle:PackagesDatesPrices a
INNER JOIN BackBundle:Packages b
WHERE a.package = b.id
AND b.id = :id
"
);
$req ->setParameter('id', $id);
return $req->getResult();
}
}
My controller:
public function packagePageAction($id)
{
$test = $this->getDoctrine()
->getManager()
->getRepository('BackBundle:PackagesDatesPrices')
->getTest($id)
;
return $this->render('BackBundle:Global:packagePage.html.twig',array(
'test' => $test
));
}
I have a OneToMany relationship between package id (field name is id) and package_dates_prices (field name is package).
I have not found a mistake yet. I tried a lot of time, but I am not very familiar with the doctrine.
Thank you for reading me and helping me.