dql

Doctrine query + LIKE expression

青春壹個敷衍的年華 提交于 2019-12-11 01:39:06
问题 I have problems to create a Doctrine Query with LIKE Expression: QUERY: $dql = "SELECT u FROM Users u JOIN u.group g WHERE g.name LIKE lower('ADMIN')"; $query = $em->createQuery($dql); $result = $query->getResult(); ERROR: QueryException: [Syntax Error] line 0, col 147: Error: Expected Doctrine\ORM\Query\Lexer::T_STRING, got 'lower' LOWER was just an example, I need to use other functions in LIKE EXPRESSION, for example, unnacent... How can I change Like Expression to support function on both

Adding an “indirectly associated” entity as a member using Doctrine ORM annotations in Symfony2

不问归期 提交于 2019-12-11 01:24:53
问题 Considering the following Symfony entities: class Continent { /** * @ORM\Id * @ORM\Column(type="integer", name="id") * @ORM\GeneratedValue(strategy="IDENTITY") */ private $id; /** * @ORM\Column(type="string", length=20, nullable=true, name="text") */ private $text; /** * @ORM\OneToMany(targetEntity="AppBundle\Entity\Country", mappedBy="continent") */ private $countries; /** * Constructor */ public function __construct() { $this->countries= new \Doctrine\Common\Collections\ArrayCollection(); }

How can I SELECT rows with MAX(Column value) in DQL?

心不动则不痛 提交于 2019-12-11 01:08:44
问题 I can not get this query in a symfony2 project that I have. My Table: id course datetime numOrden ---|-----|------------|-------- 1 | 1º | 04/11/2016 | 1 2 | 2º | 04/11/2016 | 2 5 | 3º | 04/11/2016 | 5 3 | 4º | 03/11/2016 | 4 4 | 5º | 03/11/2016 | 3 I need to get the course whose value in the "numOrden" column is the maximum( in this case it would be the 3rd course). For this I have used the following query in Doctrine2: public function findCourse() { return $this->getEntityManager()-

Doctrine DQL Delete from relation table

不问归期 提交于 2019-12-10 16:13:21
问题 Using Doctrine 2 and Symfony 2.0. I have two Doctrine entities (let's suppose EntityA and EntityB). I have a ManyToMany relation between them. So a EntityA_EntityB table has been created in database. Using DQL or QueryBuilder, how can I delete from that relation table EntityA_EntityB? Docrtine offers something like this to perform something similar: ->delete() ->from('EntityA a') ->where('a.id', '?', $id); But I don't really get how to perform the deletion of row from the relation table. 回答1:

Doctrine DQL and Namespaces (relative only?)

蓝咒 提交于 2019-12-10 13:57:52
问题 i noticed that if i try to do soemthing like $query = $em->createQuery('SELECT u FROM \Application\Entities\User u'); i get [Semantical Error] line 0, col 14 near '\Application\Entities\User': Error: Class '\' is not defined. if i do $query = $em->createQuery('SELECT u FROM Application\Entities\User u'); its ok. so the question is, can i say that DQL only accepts relative namespaces in DQL statements? 回答1: i found the answer at doctrine forums There are no "relative" namespaces in strings It

How to ORDER BY DateTime in Doctrine 2?

╄→гoц情女王★ 提交于 2019-12-10 13:56:13
问题 I'm looking to execute the following query: $qb = $this->getEntityManager()->createQueryBuilder(); $qb->select( 'e' ) ->from( 'Entity\Event', 'e' ) ->setMaxResults( $limit ) ->setFirstResult( $offset ) ->orderBy('e.dateStart', 'ASC'); $events = $qb->getQuery()->getResult(); Where /** * User * * @ORM\Table(name="event") * @ORM\Entity(repositoryClass="Repositories\EventRepository") */ class Event { /** * @var \DateTime * * @ORM\Column(name="date_start", type="datetime", precision=0, scale=0,

Doctrine 2 JOIN ON error

北战南征 提交于 2019-12-10 11:36:28
问题 I try to execute this query in my CompanyRepository $qb = $this->_em->createQueryBuilder(); $qb->select(array('c', 'ld')) ->from('Model\Entity\Company', 'c') ->leftJoin('c.legaldetails', 'ld', \Doctrine\ORM\Query\Expr\Join::ON, 'c.companyid=ld.companyid'); $query = $qb->getQuery(); echo($query->getSQL()); When I try to do it I having error: Fatal error: Uncaught exception 'Doctrine\ORM\Query\QueryException' with message '[Syntax Error] line 0, col 69: Error: Expected end of string, got 'ON''

Get random records with Doctrine

我们两清 提交于 2019-12-10 02:12:08
问题 I wonder how to get a random number of Members from a Group, but I do not know what is the best way to do this, and I think ORDER BY RAND() is not the best alternative, as a Group can have more than 100,000 Members, performing this type of query could be very slow. I found this way to make using SQL, but I do not know how to do the same thing in DQL: How can i optimize MySQL's ORDER BY RAND() function? 回答1: I'm not aware of any way to ORDER BY RAND() "efficiently" from Doctrine. In your

Doctrine query distinct related entity

爷,独闯天下 提交于 2019-12-09 16:55:25
问题 I'm probably overlooking something very simple and just been staring at it too much, but I can't get this DQL query to work. I get an exception stating: Cannot select entity through identification variables without choosing at least one root entity alias. Here's my query. User has a many-to-one relation to Group. Note that this is a unidirectional relation! That may make no sense to you, but it makes sense in our domain logic. SELECT DISTINCT g FROM Entity\User u LEFT JOIN u.group g WHERE u

Doctrine 2 JOIN ON error

廉价感情. 提交于 2019-12-08 12:24:29
I try to execute this query in my CompanyRepository $qb = $this->_em->createQueryBuilder(); $qb->select(array('c', 'ld')) ->from('Model\Entity\Company', 'c') ->leftJoin('c.legaldetails', 'ld', \Doctrine\ORM\Query\Expr\Join::ON, 'c.companyid=ld.companyid'); $query = $qb->getQuery(); echo($query->getSQL()); When I try to do it I having error: Fatal error: Uncaught exception 'Doctrine\ORM\Query\QueryException' with message '[Syntax Error] line 0, col 69: Error: Expected end of string, got 'ON'' in /home/raccoon/web/freetopay.dev/www/class/new/library/Doctrine/ORM/Query/QueryException.php on line