Category : doctrine

In Sylius, translatable entities use an ArrayCollection to handle translations, for example Product entity has ProductTranslation entities in translations attribute. Given an already hydrated entity $object from the database we have one item in $object->translations. Now, I want to add another existing translation into my $object from the database. $qb = $this->createQueryBuilder(‘o’); $qb ->addSelect(‘fallback_translation’) ->innerJoin( ..

Read more

I am trying to figure out how to count instalments attached to the contract and then return it in the result if there are less than 2. ->select(‘cc’) ->addSelect(‘COUNT(cci) AS HIDDEN numberOfInstalments’) ->from(‘AppBundle:ClientContract’, ‘cc’) ->innerJoin(‘AppBundle:ClientContractInstalment’, ‘cci’, ‘WITH’, ‘cci.clientContract = cc’) ->andHaving(‘numberOfInstalments < :numberOfRequiredInstalments'( ->setParameter(‘numberOfRequiredInstalments’, 2) ->getResult() The code from above works well when I add ..

Read more

I have a method in Doctrine repository to search a person like this: function search($value) { $qb = $this->createQueryBuilder(‘p’); $qb->where($qb->expr()->like( ‘LOWER(p.lastName)’, "’%" . mb_strtolower($value) . "%’")); } Example: No Name Last name 1 Luis Sanchez 2 David S├ínchez When I use this method and the input is ‘Sanchez’ only returns record No. 1, and if ..

Read more

In Symfony, i used to enable query results cache this way: Configuration in doctrine.yaml doctrine: orm: metadata_cache_driver: apcu result_cache_driver: apcu query_cache_driver: apcu services: doctrine.result_cache_provider: class: SymfonyComponentCacheDoctrineProvider public: false arguments: – ‘@doctrine.result_cache_pool’ doctrine.system_cache_provider: class: SymfonyComponentCacheDoctrineProvider public: false arguments: – ‘@doctrine.system_cache_pool’ framework: cache: pools: doctrine.result_cache_pool: adapter: cache.app doctrine.system_cache_pool: adapter: cache.system Enabling result caching in entity repository: $builder ..

Read more