I am new to symfony2
How do i go about re-using an entity in multiple other entities?
Say, for example (this is actually the case)
That i have an entity called CustomVar
My project has projects, categories, products.
I want my project to hold customvars (onetomany) and my product to also hold customvars (onetomany):
project 1:n customvar
product 1:n customvar
So that when accessing my product, I have access to the custom vars on project level, alswell as those on product level.
I am assuming these would both use the same object, but how do i properly annotate and use this?
So you want CustomVar to relate to both Product and Project?
In our Project (or product), you would have this code:
If your product and project are related, you could now do $product->getProject()->getCustomVars() as well as $product->getCustomVars() and works with the returned ArrayCollections.
If you want it to only relate to one of the two objects, you could have the setters check if another relation is set (by testing project and product variables) and then handling it your way (throwing exception, silently doing nothing and so on).