mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Automatically apply a custom sql-function on a property inside an entity #5403
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @mutale on GitHub (Jan 31, 2017).
Originally assigned to: @Ocramius on GitHub.
Enable to wrap entity property (database value of field) with a custom sql-function (that's known by dql),
Use case:
Translating a value when get data with findAll().
Suggestion:
Wrapping the term value with sql function in select fields.
Example:
config.yml:
Entity:
@Ocramius commented on GitHub (Jan 31, 2017):
@mutale can you please rephrase/clarify what you want here? I don't understand what you'd want to achieve with this.
@mutale commented on GitHub (Jan 31, 2017):
The goal is to translate terms from DB.
for example in menu_items table the "mi_term" value will be something like "M:I:GROUPS", but in translation table there is a translation for that term to any language.
There is already a function in the Mysql called "translate_term(term, language)".
I've added it to dql successfully and I can use it in the entity repository, but if I want to simply get all menus with its items by findAll() I need some fields to use that function as well.
Hope I was clearer.
@Ocramius commented on GitHub (Jan 31, 2017):
This is already implemented in https://github.com/Atlantic18/DoctrineExtensions/blob/v2.4.26/doc/translatable.md (via listeners).
It's generally a bad idea to push these concerns down to the storage layer, but please look at the already existing solution. Closing here.