doctrine-query

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

怎甘沉沦 提交于 2019-12-31 00:43:27
问题 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? 回答1: The findAll() method does not have any parameters.

'where not in' query with doctrine query builder

假装没事ソ 提交于 2019-12-29 04:12:25
问题 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(); 回答1: You need to use query builder expressions, and this means you need access to the query builder object.

Error: Invalid PathExpression. Must be a StateFieldPathExpression.

安稳与你 提交于 2019-12-24 14:34:59
问题 I'm working on a symfony project entity with query builder . When I try to run this function I get this issue. [Semantical Error] line 0, col 9 near 'category FROM': Error: Invalid PathExpression. Must be a StateFieldPathExpression. public function json_filterAllproductsAction() { $search = ""; $category = 1; //Combine tables and create the query with querybuilder $em = $this->container->get('doctrine.orm.entity_manager'); $qb = $em->createQueryBuilder(); $qb->select('p.category') ->from(

Get elements from LazyLoadCollection

给你一囗甜甜゛ 提交于 2019-12-24 00:48:47
问题 I have found Doctrine\Common\Collections\Criteria to be a very useful concept, if they worked for me. In a symfony controller, I am calling this code: $criteria = Criteria::create() ->where(Criteria::expr()->gt('position', 0)) ->orderBy(['riskPosition', Criteria::ASC]); $positions= $this->getDoctrine()->getRepository(DataCategory::class)->matching($criteria); dump($positions->count()); // dumps 1, correct! dump($positions); foreach($positions as $r) dump($r); // -> Unrecognized field: 0 dump(

Doctrine Query to find total number of Result in MySQL with LIMIT

元气小坏坏 提交于 2019-12-23 07:27:08
问题 I am trying to fetch the total number of rows found for specific query when LIMIT is applied. I successfully found the answer in PHP/MySQL, But I am not able to conver the logic in Zend/Doctrine. I am working with Doctrine 2.3/Zend 1.12. I dont want to use two different Queries to find the result: PHP CODE: <?php $con = mysql_connect('localhost', 'root', ''); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("myproject", $con); $sql = "SELECT SQL_CALC_FOUND_ROWS *

Doctrine QueryBuilder - Exclude articles linked to specific themes

南楼画角 提交于 2019-12-13 17:54:49
问题 I'm working on a Symfony2 project using Doctrine2. I have a 'article' and a 'theme' table in a many-to-many relationship. I am trying to get every articles except those linked to theme 35. $query = $this->createQueryBuilder('art') ->join('art.themes', 'the') ->where('the != '.35) ->getQuery() ->getResult(); This request only works when my article has only one theme. If the article has more than one (for example theme 35 + theme 36), it's not excluded from the results. How can I fix this? Here

Return all rows where the entire list of a relation matches (as opposed to any combination of)

谁说胖子不能爱 提交于 2019-12-11 20:16:30
问题 With the following simple table structure: Data ---------- id Tag ---------- id TaggedData ---------- id tag_id data_id If I had a list of Tag ids, how would I fetch every row of Data where every row of Tag in my list has a relation to a row of Data matched and not a subset thereof? Here's the query I have right now that doesn't work: SELECT Data.* FROM Data LEFT JOIN TaggedData ON (Data.id = TaggedData.data_id) LEFT JOIN Tag ON (Tag.id = TaggedData.tag_id) WHERE Tag.id IN ('1' , '2')

Using RAND() function from SQL with Doctrine2

北城余情 提交于 2019-12-11 11:19:59
问题 I've been stuck with this for about 10 hours I need to use this query (an optimized version of ORDER BY RAND) public function findAllRandom() { return $this->getEntityManager() ->createQuery( 'SELECT p FROM GabrielUploadBundle:Image p WHERE RAND() < 0.0001 ORDER BY RAND() LIMIT 20') ->getResult(); } And of course since I'm using DQL I need to implement the RAND() function <?php namespace Gabriel\UploadBundle\DoctrineFunctions; use Doctrine\ORM\Query\Lexer; /** * RandFunction ::= "RAND" "(" ")

Join queries in Doctrine on tables without specified relations

跟風遠走 提交于 2019-12-11 10:27:12
问题 I have two tables that do not have a relation defined with each other in the schema.yml. However, table 1 has a foreign key reference to the primary key of table 2. Clearly, I goofed up by not designing the database well, but now it's mitigation time. I must do a left join between the two tables coupled with a where clause that will retrieve the select rows I want. And to do this, I do: Doctrine_Query::create()->select('t.*, l.lid')->from('Taxonomy t')->leftJoin('t.Cid c') ->leftJoin('c

Doctrine 2 Self Join Query

倖福魔咒の 提交于 2019-12-11 02:29:09
问题 I'm still pretty new to Doctrine and I'm trying to retrieve a suggest list of users to follow. So basically, given an user A, I need to select all users that are followed by the users that user A follow, excluding users that user A already follow. How could I do that with Doctrine query builder ? class User { ... /** * @ORM\ManyToMany(targetEntity="User", inversedBy="followees") * @ORM\JoinTable(name="user_followers", * joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id",