当前位置: 首页>>代码示例>>PHP>>正文


PHP EntityManager::createNativeQuery方法代码示例

本文整理汇总了PHP中Kdyby\Doctrine\EntityManager::createNativeQuery方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManager::createNativeQuery方法的具体用法?PHP EntityManager::createNativeQuery怎么用?PHP EntityManager::createNativeQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Kdyby\Doctrine\EntityManager的用法示例。


在下文中一共展示了EntityManager::createNativeQuery方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: searchByTag

 /**
  * Method used for search functionality
  *
  * @param int $tagID
  * @return array
  */
 public function searchByTag($tagID)
 {
     $rsm = new ResultSetMappingBuilder($this->em);
     $rsm->addEntityResult(Page::class, 'p');
     $rsm->addFieldResult('p', 'id', 'id');
     $rsm->addFieldResult('p', 'title', 'title');
     $rsm->addFieldResult('p', 'intro', 'intro');
     $rsm->addFieldResult('p', 'intro_html', 'introHtml');
     //$rsm->addFieldResult('p', 'text', 'text');
     $rsm->addMetaResult('p', 'author', 'author');
     $rsm->addMetaResult('p', 'url', 'url');
     $rsm->addFieldResult('p', 'created_at', 'createdAt');
     $rsm->addFieldResult('p', 'is_draft', 'isDraft');
     $rsm->addFieldResult('p', 'published_at', 'publishedAt');
     $rsm->addFieldResult('p', 'allowed_comments', 'allowedComments');
     $rsm->addScalarResult('commentsCount', 'commentsCount', 'integer');
     $rsm->addIndexByColumn('p', 'id');
     $rsm->addJoinedEntityResult(Locale::class, 'l', 'p', 'locale');
     $rsm->addFieldResult('l', 'locale_id', 'id');
     $rsm->addFieldResult('l', 'locale_name', 'name');
     $rsm->addFieldResult('l', 'locale_code', 'code');
     $rsm->addFieldResult('l', 'locale_lang', 'lang');
     $rsm->addFieldResult('l', 'locale_default', 'default');
     $nativeQuery = $this->em->createNativeQuery('SELECT p.id, p.title, p.intro, p.intro_html, p.author, p.url,
                 p.created_at, p.is_draft, p.published_at,
                 p.allowed_comments, COUNT(c.page) AS commentsCount,
                 l.id AS locale_id, l.name AS locale_name, l.code AS locale_code,
                 l.lang AS locale_lang, l.default AS locale_default
          FROM (
             SELECT pts.page_id, pts.tag_id
             FROM page_tag pts
             WHERE pts.tag_id = :id
             GROUP BY pts.page_id
          ) AS pt
          JOIN page p ON (p.id = pt.page_id AND p.is_draft = 0 AND p.published_at <= NOW())
          JOIN locale l ON (l.id = p.locale)
          LEFT JOIN comment c ON (c.page = pt.page_id)
          GROUP BY pt.page_id', $rsm)->setParameter('id', $tagID);
     $pages = $nativeQuery->getResult();
     $this->em->createQuery('SELECT PARTIAL page.{id}, tags FROM ' . Page::class . ' page
          LEFT JOIN page.tags tags INDEX BY tags.id
          WHERE page.id IN (:ids)')->setParameter('ids', array_keys($pages))->execute();
     return $pages;
 }
开发者ID:blitzik,项目名称:CMS,代码行数:50,代码来源:PageFacade.php

示例2: findRolesThatAreNotParents

 /**
  * @return Role[]
  */
 public function findRolesThatAreNotParents()
 {
     $rsm = new ResultSetMappingBuilder($this->em);
     $rsm->addEntityResult(Role::class, 'r');
     $rsm->addFieldResult('r', 'id', 'id');
     $rsm->addFieldResult('r', 'name', 'name');
     $rsm->addJoinedEntityResult(Role::class, 'p', 'r', 'parent');
     $rsm->addFieldResult('p', 'parent_id', 'id');
     $rsm->addFieldResult('p', 'parent_name', 'name');
     $nativeQuery = $this->em->createNativeQuery('
         SELECT r.id, r.name, p.id AS parent_id, p.name AS parent_name
         FROM role r
         LEFT JOIN role p ON (p.id = r.parent_id)
         WHERE r.id NOT IN(
             SELECT r2.parent_id FROM role r2 WHERE r2.parent_id IS NOT NULL
         )
     ', $rsm);
     return $nativeQuery->getResult();
 }
开发者ID:blitzik,项目名称:CMS,代码行数:22,代码来源:UserFacade.php


注:本文中的Kdyby\Doctrine\EntityManager::createNativeQuery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。