query-builder

ORMLite - Parenthesis in join where clauses

元气小坏坏 提交于 2019-12-06 09:09:38
I would like to join three tables using QueryBuilder.join and QueryBuilder.joinor but I want parenthesis in the where clause something like this: WHERE first_table_where AND (second_table_where OR third_table_where) but it seems that is not possible. Perhaps I am missing something. Any help would be appreciated. Daber I guess that is a part of the doc you have been looking for... If you want to do complex queries linearly, you can even use Reverse Polish Notation (of all things). There is a Where.or(int) and Where.and(int) methods which do the operation on the previous number of specified

How to use wildcards in createQueryBuilder?

拈花ヽ惹草 提交于 2019-12-06 07:15:46
问题 In my repository class i use: public function getItemsByTag($tag) { $qb = $this->createQueryBuilder('c') ->select('c') ->where('c.tags LIKE %bipolar%') ->addOrderBy('c.id'); return $qb->getQuery() ->getResult(); } But unfortunately this doesn't work.. Anybody knows how this can work? Or do I have to build a custom query without the QueryBuilder? Thanks! 回答1: If you don't want to substitute your query with variables but use a static string you have to put the string in apostrophes. You have to

Search DAM assets and Cq pages using lastModified date | QueryBuilder

白昼怎懂夜的黑 提交于 2019-12-06 07:04:15
问题 I am querying the cq pages and assets based on the last modified date. Here is the the text that has to be put in query builder debugger: fulltext=geometrix 1_group.p.or=true 1_group.1_group.p.and=true 1_group.1_group.path=/content 1_group.1_group.type=cq:Page 1_group.1_group.relativedaterange.property=jcr:content/cq:lastModified 1_group.1_group.relativedaterange.lowerBound=-1M 1_group.2_group.p.and=true 1_group.2_group.path=/content/dam 1_group.2_group.type=dam:Asset 1_group.2_group

Symfony2 and Doctrine2 - QueryBuilder with relational entities

给你一囗甜甜゛ 提交于 2019-12-06 04:17:36
In my Symfony2 project, I have a query like this: $paperQB = $this->createQueryBuilder( 'p' ) ->select('p') ->where("p.title LIKE :q OR p.keywords LIKE :q OR p.abstract LIKE :q OR p.id LIKE :q") ->setFirstResult( $first_result ) ->setMaxResults( $papers_per_page ) ->orderBy($sort_by_culumn, $sort_by_order) ->setParameter('q', '%'.$q.'%'); Everything is fine there, but In my paper entity, I have a many to one relation with the section entity. So, I would like to get also: "OR p.section.name LIKE :q" How is this possible, should I use a join in order to do that? The query bilder does not know

Doctrine2: [Semantical Error] Cannot select entity through identification variables without choosing at least one root entity alias

谁说胖子不能爱 提交于 2019-12-06 03:40:30
This is my query with query builder, and it works perfectly, bringing all the results of user table and the modules table, which has a many to many association: public function getUser($id){ $qb = $this->getEm()->createQueryBuilder() ->select('u', 'm') ->from('Adm\Entity\User', 'u') ->join('u.modules', 'm') ->where('u.id = ?1') ->setParameters(array(1 => $id)); $result = $qb->getQuery()->getResult(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY); return $result; } But when i try to select specific fields from user like this: public function getUser($id){ $qb = $this->getEm()->createQueryBuilder() -

Query Builder / DQL not working with INNER JOIN - Syntax Issue

梦想与她 提交于 2019-12-06 02:51:11
问题 I know I have a syntax isse here however I cant figure it out. I'm trying to do a SELECT and INNER JOIN of 5 tables but Symfony is complaining about the Entities in the JOIN are used before being defined. Actual error is as follows: [Semantical Error] line 0, col 121 near 'I ON C.id = ': Error: Identification Variable MySiteBundle:Items used in join path expression but was not defined before. Here is the PHP code. Note: I have shortened this query to two columns, two tables, and one join to

Doctrine 2.5 Unexpected association fetch behavior [Symfony 3]

橙三吉。 提交于 2019-12-06 01:37:12
I have 3 entities associated this way: Don't worry, I've set associations using annotations, but I thought the following mix would be lighter/cleaner to expose my issue Post @ORM\ManyToOne(targetEntity="User", fetch="EAGER") - author User @ORM\OneToOne(targetEntity="Vip", mappedBy="user", fetch="EAGER") - vip Vip # Notice that the primary key of vip is a foreign key on User primary @ORM\id @ORM\OneToOne(targetEntity="User", inversedBy="peliqan", fetch="EAGER") @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false) - user As you can see, all is set to be eagerly fetched.

How to create an AND button that adds a AND statement to a query?

杀马特。学长 韩版系。学妹 提交于 2019-12-05 21:21:53
I'm making some type of query builder and I want to implement a button to add a AND statement to my query. I made a version where I have 1 AND statement implemented but it's a bit devious and I want the user to have the ability to do more than one AND statement. This the code I have at the moment. UPDATED This is my .php file: <?php include "connect.php"; //Ophalen van de waarden uit de tabel(len) en veld(en) $table = $_GET['tableSelected']; $field = $_GET['fieldSelected']; $attribute = $_GET['attributeSelected']; $operator = $_GET['operatorSelected']; $fieldList = $_GET['fieldList'];

How to use the ORMLite query builder to get the total records in a table

纵饮孤独 提交于 2019-12-05 09:33:45
问题 Similar to select count(*) from tablename; what should be query in ORMLITE i tried something like int total = dao.queryBuilder().("select count(*)"); 回答1: How to use the ORMLite query builder to get the total records in a table ORMLite has a Dao.countOf() method that returns the total number of rows in a table: long numRows = dao.countOf(); You can also count the number of rows in a custom query by calling the countOf() method on the Where or QueryBuilder object. // count the number of lines

Symfony2 subquery within Doctrine entity manager

岁酱吖の 提交于 2019-12-05 06:50:37
I need to perform this query: SELECT * FROM (SELECT * FROM product WHERE car = 'large' ORDER BY onSale DESC) AS product_ordered GROUP BY type In Symfony2 using the entity manager. My basic query builder would be : $query = $em->getRepository('AutomotiveBundle:Car') ->createQueryBuilder('p') ->where('pr.car = ?1') ->andWhere('pr.status = 1') ->orderBy('pr.onSale', 'DESC') ->setParameter(1, $product->getName()) ->groupBy('p.type') ->getQuery(); But I cannot work out how to add in a subquery to this. Ive tried making a separate query and joining it like: ->andWhere($query->expr()->in('pr.car = ?1