doctrine-query

Expression mysql NOW() in Doctrine QueryBuilder

纵饮孤独 提交于 2019-12-03 22:09:47
How to use the expression mysql NOW() in doctrine querybuilder? Mats Rietdijk In Doctrine2 you have to use one of the following instead of NOW() . This: CURRENT_TIMESTAMP() Or: ... createQuery(...'WHERE x.date = :now') ->setParameter('now', new \DateTime('now')) ... If you want only time or only date use one of those: CURRENT_TIME() and CURRENT_DATE() Documentation can be found here . Using query builder it would look like this: $qb ->select('B') ->from('RandomBundle:Banana', 'B') ->where( $qb->expr()->gt('B.expiresAt', ':now') ) ->setParameter('now', '\'CURRENT_TIMESTAMP()\''); Note: extra

Doctrine INNER/LEFT JOIN two tables

故事扮演 提交于 2019-12-02 16:38:10
问题 I am learning from this Question but facing issues with many operations in between: doctrine 2 query builder and join tables Below is my Questions. I am looking for help in my previous question too.. Thanks for those who helped me in solving the issues. I am creating a big Query in Doctrine 2.3, The operations are not familiar to me.But I learnt with the help of many persons. Currently I am facing issue with Inner Joint between 3 tables. My Joint: SELECT * FROM user AS u LEFT JOIN source AS s

Doctrine INNER/LEFT JOIN two tables

杀马特。学长 韩版系。学妹 提交于 2019-12-02 10:03:35
I am learning from this Question but facing issues with many operations in between: doctrine 2 query builder and join tables Below is my Questions. I am looking for help in my previous question too.. Thanks for those who helped me in solving the issues. I am creating a big Query in Doctrine 2.3, The operations are not familiar to me.But I learnt with the help of many persons. Currently I am facing issue with Inner Joint between 3 tables. My Joint: SELECT * FROM user AS u LEFT JOIN source AS s ON u.user_source_fk=s.source_id LEFT JOIN area AS a ON s.source_node_fk = a.area_id; The above Query

How to get Array Results in findAll() - Doctrine?

早过忘川 提交于 2019-12-01 18:35:31
I need to fetch all records in database as Array using findAll() in Doctrine, My Query is Something like this $result = $this->getDoctrine() ->getRepository('CoreBundle:Categories') ->findAll(\Doctrine\ORM\Query::HYDRATE_ARRAY); even if set Hydration Mode to HYDRATE_ARRAY , am getting results as objects array:4 [▼ 0 => Categories {#323 ▶} 1 => Categories {#326 ▶} 2 => Categories {#329 ▶} 3 => Categories {#332 ▶} ] what mistake i made? The findAll() method does not have any parameters. You can, for example, use the repository's createQueryBuilder() method to achieve what you want to do: $query

Magic Doctrine2 finders when field has underscore?

做~自己de王妃 提交于 2019-12-01 04:06:43
问题 I'm having problems using find*() magic methods of Doctrine2 when the field has an underscore in between. $repository->findByName("Hello"); // Works $repository->findByIsEnabled(true); Entity 'Acme\SecurityBundle\Entity\Package' has no field 'isEnabled'. You can therefore not call 'findByIsEnabled' on the entities' repository. This is the simple entity definition in YAML for replicating the error: Acme\SecurityBundle\Entity\Package: type: entity repositoryClass: Acme\SecurityBundle\Repository

How to write union query in doctrine?

泄露秘密 提交于 2019-11-30 19:38:29
I want to use union in doctrine, i searched a lot but didn't get any success, this is my union query in sql, how to convert this query in doctrine? select * from (select orderid,tutorialId,points,allow_multiple,question,answer1,image1,correct1,answer2,image2,correct2,answer3,image3,correct3,answer4,image4,correct4,answer5,image5,correct5,'1' as istest,'' as content,'' as media,'' as media_type_id from tutorial_test union select orderid,tutorialId,'0' as istest,content,media,media_type_id,'' as points,'' as allow_multiple,'' as question,'' as answer1,'' as image1,'' as correct1,'' as answer2,''

'where not in' query with doctrine query builder

戏子无情 提交于 2019-11-28 21:08:39
Im trying to reproduce this query: SELECT * FROM `request_lines` where request_id not in( select requestLine_id from `asset_request_lines` where asset_id = 1 ) in doctrine query builder, I am stuck on the where request_id not in(select I currently have: $linked = $em->createQueryBuilder() ->select('rl') ->from('MineMyBundle:MineRequestLine', 'rl') ->where() ->getQuery() ->getResult(); You need to use query builder expressions, and this means you need access to the query builder object. Also, the code is easier to write if you generate the subselect list ahead of time: $qb = $em-

Regex with Doctrine 2 query builder?

拟墨画扇 提交于 2019-11-28 12:00:48
As per the title, how would one match on a regular expression with the Doctrine 2 query builder? Basically I'm trying to generate unique slugs. Here is my current implementation. I generate the slug. I then check to see if there are any slugs in use like this slug. If there are, I will append a -{number} to the end of the slug where {number} is the lowest number not already in use. $qb->select(array('partial o.{id, slug}')) ->from('Foo\Bar\Entity\Object', 'o') ->where($qb->expr()->like('o.slug', ':slug')); $slug = new SlugNormalizer($text); $qb->setParameter('slug', $slug->__toString().'-%');

How to fetch class instead of array in Doctrine 2

浪尽此生 提交于 2019-11-28 07:37:16
I am able to fetch my data from database by using this structure: $user = $this->getDoctrine() ->getRepository('AcmeDemoBundle:Emails') ->find(8081); When I do that, I am able to get my data like this: $user->getColumnNameHere(); Basically I am able to use Entity Class. But if I want to use QueryBuilder instead of find I am only getting associative arrays. $product->createQueryBuilder('p') ->setMaxResults(1) ->where('p.idx = :idx') ->select('p.columnNameHere') ->setParameter('idx', 8081) ->orderBy('p.idx', 'DESC') ->getQuery(); $product = $query->getResult(); $product returnds as array. Is it

Doctrine: Cannot select entity through identification variables without choosing at least one root entity alias

牧云@^-^@ 提交于 2019-11-27 23:34:39
I'm using the following code in the query builder , to select an average of score values, and the category entity to which that average belongs: $queryBuilder = $this->createQueryBuilder('s') ->resetDQLPart('select') ->select('AVG(s.score) as score, partial c.{reviewCategoryID} as cat') ->setParameter('status', ReviewStatusType::ACCEPTED) ->join('s.review', 'r') ->join('s.category', 'c') ->where('r.campsite = :campsite') ->andWhere('r.status = :status') ->setParameter('campsite', $campsite) ->groupBy('c.reviewCategoryID'); $campsite is an entity to which a review belongs, while scores belong