I'm facing a trouble with symfony 2.8.7, in order to make a simple join between two tables 'users' and 'post' with doctrine annotations I've made some entity files so firstly user entity :
<?php
namespace Blog\FrontBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* user
*
* @ORM\Table(name="user")
* @ORM\Entity(repositoryClass="Blog\FrontBundle\Repository\userRepository")
*/
class user
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var post
*
* @ORM\OneToMany(targetEntity="post", mappedBy="user")
* @ORM\JoinColumn(onDelete="CASCADE")
*/
private $post;
/**
* @var string
*
* @ORM\Column(name="username", type="string", length=255)
*/
private $username;
/**
* @var string
*
* @ORM\Column(name="email_user", type="string", length=255)
*/
private $emailUser;
/**
* @var string
*
* @ORM\Column(name="passwd", type="string", length=255)
*/
private $passwd;
/**
* @var \DateTime
*
* @ORM\Column(name="date_born", type="date")
*/
private $dateBorn;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set username
*
* @param string $username
*
* @return user
*/
public function setUsername($username)
{
$this->username = $username;
return $this;
}
/**
* Get username
*
* @return string
*/
public function getUsername()
{
return $this->username;
}
/**
* Set emailUser
*
* @param string $emailUser
*
* @return user
*/
public function setEmailUser($emailUser)
{
$this->emailUser = $emailUser;
return $this;
}
/**
* Get emailUser
*
* @return string
*/
public function getEmailUser()
{
return $this->emailUser;
}
/**
* Set passwd
*
* @param string $passwd
*
* @return user
*/
public function setPasswd($passwd)
{
$this->passwd = $passwd;
return $this;
}
/**
* Get passwd
*
* @return string
*/
public function getPasswd()
{
return $this->passwd;
}
/**
* Set dateBorn
*
* @param \DateTime $dateBorn
*
* @return user
*/
public function setDateBorn($dateBorn)
{
$this->dateBorn = $dateBorn;
return $this;
}
/**
* Get dateBorn
*
* @return \DateTime
*/
public function getDateBorn()
{
return $this->dateBorn;
}
}
and for the post entity :
<?php
namespace Blog\FrontBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* post
*
* @ORM\Table(name="post")
* @ORM\Entity(repositoryClass="Blog\FrontBundle\Repository\postRepository")
*/
class post
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var int
*
* @ORM\ManyToOne(targetEntity="user", inversedBy="post")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
private $user;
/**
*
* @ORM\OneToMany(targetEntity="comment", mappedBy="post")
* @var comment
*/
private $comment;
/**
* @var string
*
* @ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* @var \DateTime
*
* @ORM\Column(name="date_post", type="date")
*/
private $datePost;
/**
* @var string
*
* @ORM\Column(name="content_post", type="text")
*/
private $contentPost;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* @param string $title
*
* @return post
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set datePost
*
* @param \DateTime $datePost
*
* @return post
*/
public function setDatePost($datePost)
{
$this->datePost = $datePost;
return $this;
}
/**
* Get datePost
*
* @return \DateTime
*/
public function getDatePost()
{
return $this->datePost;
}
/**
* Set contentPost
*
* @param string $contentPost
*
* @return post
*/
public function setContentPost($contentPost)
{
$this->contentPost = $contentPost;
return $this;
}
/**
* Get contentPost
*
* @return string
*/
public function getContentPost()
{
return $this->contentPost;
}
}
The result doesn't fetch the posts associated to users, and I see in the console that the query didn't make the join query :
SELECT
u0_.id AS id_0,
u0_.username AS username_1,
u0_.email_user AS email_user_2,
u0_.passwd AS passwd_3,
u0_.date_born AS date_born_4
FROM
user u0_
What do you think I've missed ? Thanks for your help I'm new to Symfony