Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6724279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:40:13+00:00 2026-05-26T09:40:13+00:00

Is it safe to change name of database column on the fly in Doctrine’s

  • 0

Is it safe to change name of database column on the fly in Doctrine’s mapping in application’s bootstrap in case I will do it for all created entity managers?

<?php
// In "every second" view sort by score2 instead of by score1 
if (rand(0, 1) % 2 === 0) {
   $entityManager->getMetadataFactory()->getMetadataFor('Advertisement')->fieldMappings['score']['columnName'] = 'score2';
}

Score attribute is used for sorting of displayed entities and I would like to do A/B testing of sorting by different database columns in the easiest way.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:40:14+00:00Added an answer on May 26, 2026 at 9:40 am

    Ok so it seems I have solution.

    The best way is probably to make own ClassMetadataFactory which is extended from \Doctrine\ORM\Mapping\ClassMetadataFactory and create EntityManagers with this ClassMetadataFactory.

    <?php
    /**
     * Implementation of Doctrine's metadata factory class for A/B testing
     */
    class ClassMetadataFactory extends \Doctrine\ORM\Mapping\ClassMetadataFactory
    {
        /**
         * Gets the class metadata descriptor for a class.
         *  
         * @param string $className The name of the class.
         * @return Doctrine\ORM\Mapping\ClassMetadata
         */
        public function getMetadataFor($className)
        {
            $metadata = parent::getMetadataFor($className);
    
            if ($className === 'Advertisement' || $className === '\Advertisement') {
                $metadata->fieldMappings['score']['columnName'] = 'score2';
                $metadata->fieldNames['score'] = 'score2';
                $metadata->columnNames['score'] = 'score2';
            }
    
            return $metadata;
        }
    }
    

    Another thing you should be aware of is Doctrine’s DQL cache!

    This is relative silly example. Next step could be to do configuration of A/B testing and some switch responsible for variant decision, but this is out of topic my question above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is ( SIGRTMIN + 1 ) safe for inter-process communication? Will it change in
Will the facebookId ever change? If not, Is it safe to use it in
My email code isn't working. <?php if(isset($_POST['send'])){ $to = info@erbimages.com ; // change all
I once attempted to change my project's default namespace in Project -> Project Name
Is it safe to change VirtualTreeView data from the secondary thread ? And if
I have a CActiveRecord model, and I need to change safe attributes list in
I could change XCode project name with the answer: https://stackoverflow.com/a/4954029/709950 . Project file (.xcodeproj)
I want to change the table name of the ActiveRecord model class during request
I see that my application has the wrong name. When I go to: Project
How safe is it to use Silverlight in production for a graphic form? Is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.