Reputation: 327
i have some little error with doctrine mapping . I have genarate entities and mapping data from console , and when i trying to get related column data it sets to null and i did not know why
Entites :
TasksCaregories :
/**
* @var \PhpTasksBundle\Entity\Tasks
*
* @ORM\OneToOne(targetEntity="PhpTasksBundle\Entity\Tasks")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="id", referencedColumnName="category_id", unique=true)
* })
*/
private $id;
Tasks :
/**
* @var \PhpTasksBundle\Entity\TasksCategories
*
* @ORM\ManyToOne(targetEntity="PhpTasksBundle\Entity\TasksCategories")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="category_id", referencedColumnName="id")
* })
*/
private $category;
Controller :
$tasks = $this->getDoctrine()
->getRepository('PhpTasksBundle:Tasks')
->findAll();
View:
{{ dump(tasks) }}
and i get empty "name" column in related array .
But i need to get not hull name from category :( Please somebody help
Upvotes: 0
Views: 64
Reputation: 2714
It's good for the relation ManyToOne between Taks -> TasksCategories (it means that one categorie may have many differents tasks (absolutely logic):
/**
* @var \PhpTasksBundle\Entity\TasksCategories
*
* @ORM\ManyToOne(targetEntity="PhpTasksBundle\Entity\TasksCategories")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="category_id", referencedColumnName="id")
* })
*/
private $category;
So, conversely, the relation TasksCategories -> Tasks could be : OneToMany or ManyToMany according to your need.
For example : you want that one Task could be attached to many Categories (ManyToMany), if not, one Task -> just one Categorie (OneToMany). I hope clear for you.
Upvotes: 1