I had trouble formulating the title of my question. Apologies for that.
I have a OneToMany association between "Catalog" and "Category". I also have a self referencing bidirectional association on Category (since a category can contain multiple categories).
The problem is that when I fetch my catalog, the categories of my catalog are empty. I thought that Doctrine could return a full result since there is a foreign key in Category.
Here's two code snippet of what I did :
My entities :
Entity Catalog
/**
* @ORM\OneToMany(targetEntity="Category", mappedBy="catalog")
**/
private $catalogCategories;
Entity Category
/**
* @ORM\ManyToOne(targetEntity="Catalog", inversedBy="catalogCategories")
* @ORM\JoinColumn(name="catalog_id", referencedColumnName="catalog_id")
**/
private $catalog;
/**
* @ORM\OneToMany(targetEntity="Category", mappedBy="categoryParent")
**/
private $categoryChildren;
/**
*
* @ORM\ManyToOne(targetEntity="Category", inversedBy="categoryChildren")
* @ORM\JoinColumn(name="category_parent_id", referencedColumnName="category_id")
**/
private $categoryParent;
My Controller
/**
* @return array
* @View()
* @ParamConverter("catalog", class="TestRESTfulAPIBundle:Catalog")
*/
public function getCatalogAction(Catalog $catalog)
{
return array('catalog' => $catalog);
}
Note that I'm using FOSRestBundle. When I simulate a HTTP request I get my Catalog in a JSON object but my catalog_categories is empty.
My question is divided in two parts : Is it possible to retrieve a complete record from my database, so my catalog contains all the categories in a recursive way.
If it is (which I think it's true), can anyone point my mistake?
I'm new to Symfony2 and english is not my native language so be indulgent with me.
Cheers.