Use of unmapped entities in Symfony2

5

I have read that the Entity folder of a bundle normally stores the entities that will be persisted (in my case, by Doctrine) in the database.

But for the ease of working with "annotations" formatting within an Entity, I have chosen to create unmapped (non-persistent) entities. In this way, I can validate an arbitrary data structure using all the conveniences of Symfony2 in the format "annotations".

So my question is: is there any contraindication for using unmapped entities (by Doctrine) within my project?

    
asked by anonymous 13.12.2013 / 21:55

2 answers

3

Response

There is no contraindication.

You can do as you are thinking by getting the benefits of the validation component.

Reflections

An "Entity" is actually a common object. Through metadata (by notes or configuration file) Doctrine does its job - without the class having to implement an interface or extend extends) a hierarchy.

So you might want to put these classes in a other folder within the Bundle, since Entity is consecrated by use as the folder where entities to be persisted reside.

In short: the question revolves around what "entities" means ... you speak in

  

unmapped (non-persistent) entities

... by me, fine, but it is known whether the name "entity" refers to an object that will be mapped / persisted to / in> "? Why not simply " unmapped in> classes not mapped "? Just do not call your objects "entities"! : -)

Conclusion

Finally, in practice you can put your classes in the "Entity" folder and use the word "entities", do not map, do not use Doctrine or ORM annotations, but use validation annotations and the Symfony 2 validation component with no problems . And you can also, as mentioned, put these classes in a folder other than Entity.

    
10.03.2014 / 02:41
1

I do not see why this could be bad, the only difference is that these entities would not be managed by Doctrine's EntityManager, right? You will use them for other functions within the project. Or are you going to use these entities in some way with Doctrine?

    
17.12.2013 / 23:11