I have tried a couple of different examples I found on forums and even on the official documentation, but just cant seem to understand and make this work.
It’s quite simple, yet anything i write does not work!
So, I have Category entity and a Site entity. One category should have many sites. Thats it, really. How to map them?
I understand I should have a field sites in Category entity as a OneToMany relationship, and category field in the Site entity as ManyToOne?
The most basic code I tried is this:
/**
* @ORM\OneToMany(targetEntity="Site", mappedBy="category")
*/
protected $sites;
/**
* @ORM\ManyToOne(targetEntity="Category")
*/
protected $category;
This gives no error when calling (in Symfony 2):
app/console doctrine:generate:entities TestSampleBundle\Entity\Category (or Site), but says:
Namespace "..." does not contain any mapped entities.
I am quite new to Doctrine, so please no insults, I agree that I might not be able to understand the examples, and they could be perfectly working, but even so, I need someone to explain this in 2 sentences, so I would know where to start from. I haven’t ever managed to make mappings work.
After looking in your pastebin I recognize you might have some issues with your namespace:
Try replacing
with
and make sure to place it in the folder
As a general advice: Always make sure your namespace matches your folder structure and your usage in symfony commands. The autoloader only works well when you pay attention to namespaces!