I'm trying to get manyToMany relationship with Doctrine and symfony. I'm new at Doctrine and Symfony. I came from Zend framework.
I've created the 3 tables: Post, PostCategory and junction table PostToCategory as you can see below.
My goal is to do inner join and to get for every post its categories. This is what I've done so far:
//CMS/GBundle/Entity/PostContent
class PostContent
{
/**
* @ORM\ManyToMany(targetEntity="CMS\GBundle\Entity\PostCategory", inversedBy="posts")
* @ORM\JoinTable(name="post_to_category")
*/
protected $categories;
public function __construct()
{
$this->categories = new ArrayCollection();
}
//CMS/GBundle/Entity/PostCategory
class PostCategory
{
/**
* @ORM\ManyToMany(targetEntity="CMS\GBundle\Entity\PostContent", mappedBy="categories")
*/
protected $posts;
public function __construct()
{
$this->posts = new ArrayCollection();
}
I would like now to create function that returns me joined data Post->PostCategories.
Where should I create function ? in PostToCategory Repository ? or somewhere else ? How should my query look like ?
I've tried a lot of options and I passed all the possible questions on Stack but I could not get it done..
Thanks in advance!
Update:
This is what i get when i do findAll method on PostContent repository.