Automatically apply a custom sql-function on a property inside an entity #5403

Closed
opened 2026-01-22 15:06:40 +01:00 by admin · 3 comments
Owner

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:

orm:
    mappings:
      AppBundle:
        type: annotation
    dql:
      string_functions:
        translate_term: AppBundle\DoctrineExtensions\Utils\TranslateTerm

Entity:

 /**
     * @var string
     *
     * @ORM\Column(name="mi_term", type="string", length=25, nullable=true)
     * @ORM\GeneratedValue(strategy="CUSTOM")
     * @ORM\CustomWrapper(class="AppBundle\DoctrineExtensions\Utils\TranslateTerm")
     */
    private $miTerm;
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: ``` orm: mappings: AppBundle: type: annotation dql: string_functions: translate_term: AppBundle\DoctrineExtensions\Utils\TranslateTerm ``` Entity: ``` /** * @var string * * @ORM\Column(name="mi_term", type="string", length=25, nullable=true) * @ORM\GeneratedValue(strategy="CUSTOM") * @ORM\CustomWrapper(class="AppBundle\DoctrineExtensions\Utils\TranslateTerm") */ private $miTerm; ```
admin added the ImprovementWon't FixQuestion labels 2026-01-22 15:06:40 +01:00
admin closed this issue 2026-01-22 15:06:43 +01:00
Author
Owner

@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.

@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.
Author
Owner

@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.

@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.
Author
Owner

@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.

@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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5403