doctrine-query

select query and count based on condition

て烟熏妆下的殇ゞ 提交于 2019-12-10 23:17:06
问题 I want to select all categories, subcategories and count the number of business that belongs to subcategory. this is the SQl query i am using. SELECT c.id, c.name, c.slug, sc.id, sc.name, sc.slug, COUNT(bsc.id) AS business_count FROM fi_category c LEFT JOIN fi_subcategory sc ON c.id = sc.category_id AND (sc.deleted_at IS NULL) LEFT JOIN fi_business_subcategory bsc ON sc.id = bsc.subcategory_id AND (bsc.deleted_at IS NULL) WHERE (c.deleted_at IS NULL) GROUP BY c.id, sc.id however there is more

Doctrine Query from Mysql

浪子不回头ぞ 提交于 2019-12-10 17:38:03
问题 I want to create a Doctrine Query: (Doctrine 2.3) SELECT * FROM `car` WHERE `plate` like '%' AND (`datetime` BETWEEN '2013-03-13 22:20:18' AND '2013-03-13 22:20:20') OR (`datetime` BETWEEN '2013-03-13 15:10:18' AND '2013-03-13 15:10:16') I tried the following but its not working: $qry = $this->manager()->createQueryBuilder() ->from($this->entity, 'e') ->select('e'); $qry->where('e.plate like :plate'); $qry->setParameter('plate', $plate); $qry->andWhere( qry->expr()->between( 'e.datetime', '

Doctrine update query with LIMIT

假如想象 提交于 2019-12-10 10:47:03
问题 I would like to do an update-query with a LIMIT like that: UPDATE anytable SET anycolumn = 'anyvalue' WHERE anothercolumn='anothervalue' LIMIT 20 How is this possible with doctrine 2.1 ? 回答1: Not doctrine specific, but maybe possible with a subquery ? UPDATE messages SET test_read=1 WHERE id IN ( SELECT id FROM ( SELECT id FROM messages ORDER BY date_added DESC LIMIT 5, 5 ) tmp ); 回答2: I found I had to fetch the connection from the entityManager and call executeUpdate: $em->getConnection()-

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

一曲冷凌霜 提交于 2019-12-10 10:08:39
问题 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

Doctrine 2 PlainValue expected

我是研究僧i 提交于 2019-12-10 02:14:04
问题 I'm having trouble executing a Doctrine DQL Query. This is the error it gives me. Doctrine\Common\Annotations\AnnotationException: [Syntax Error] Expected PlainValue, got 'integer' at position 13 in property Base\Session::$lifetime. My code looks like this: $query = $em->createQuery("SELECT s FROM Base\Session s WHERE s.session = \"$id\""); Where $id is the current session_id. My Model looks like: namespace Base; /** @Entity @Table(name="session") */ class Session extends Skeleton { /** * @Id

Doctrine 2.5 Unexpected association fetch behavior [Symfony 3]

。_饼干妹妹 提交于 2019-12-07 16:29: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",

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() -

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.

Expression mysql NOW() in Doctrine QueryBuilder

南楼画角 提交于 2019-12-05 08:50:26
问题 How to use the expression mysql NOW() in doctrine querybuilder? 回答1: 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. 回答2: Using query builder it would look like this: $qb ->select('B') ->from('RandomBundle:Banana', 'B') ->where( $qb-

Doctrine 2 PlainValue expected

隐身守侯 提交于 2019-12-05 00:23:56
I'm having trouble executing a Doctrine DQL Query. This is the error it gives me. Doctrine\Common\Annotations\AnnotationException: [Syntax Error] Expected PlainValue, got 'integer' at position 13 in property Base\Session::$lifetime. My code looks like this: $query = $em->createQuery("SELECT s FROM Base\Session s WHERE s.session = \"$id\""); Where $id is the current session_id. My Model looks like: namespace Base; /** @Entity @Table(name="session") */ class Session extends Skeleton { /** * @Id @Column(type="integer") * @GeneratedValue(strategy="AUTO") */ protected $id; /** @Column(length=32) */