简体   繁体   中英

Doctrine2 - relation depending on parameter

I would like to know what is the best way to have an entity with 1:N relation to another entity but additionally depending on a parameter.

For example I have product entity and product_description entity, which depends on product_id and also on language (2 char code). Another examples would be manufacturer and manufacturer_description , category and category_description . There is a lot of it - you got the idea.

I though about extending EntityRepository class and adding automatic join based for example on an annotation. I'm just not sure if this is the "correct way" to do what I want. Can you suggest better solution? Another though was just to have method getDescription($language) in product entity but to me it just doesn't look as best solution, especially because I want to load the language-dependent content in 90% cases with all other information. Getting that content in separate query would just create unnecessary load.

Thank you for your suggestions.

There is a translatable extensions for doctrine. I've never used it but it looks like it might address your use case:

http://www.doctrine-project.org/2010/11/18/doctrine2-behavioral-extensions.html

See also

https://github.com/l3pp4rd/DoctrineExtensions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM