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