duannuo7878 2013-07-01 04:53
浏览 23
已采纳

在Symfony2存储库中访问自定义查询[关闭]

This is my query for getting a random product:

 public function getRelatedProducts()
  {
    $em = $this->getDoctrine()->getManager();
        $max = $em->createQuery('SELECT MAX(p.id) FROM GlassShopBundle:Product p')->getSingleScalarResult();
        return $em->createQuery('SELECT q FROM GreenMonkeyDevGlassShopBundle:Product p WHERE p.id >= :rand ORDER BY p.id ASC')
            ->setParameter('rand',rand(0,$max))
            ->setMaxResults(1)
            ->getSingleResult()
            ->getResults(); 
    }

I get a Undefined method 'getRelatedByCategory'. The method name must start with either findBy or findOneBy! Error, which to me is strange since other queries hav worked for me and I have not really deviated. Any thoughts?

  • 写回答

1条回答 默认 最新

  • douzhunlan5930 2013-07-01 13:54
    关注

    Possible that is a typo in called function name. Method named getRelatedProducts, you call getRelatedByCategory.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)