草庐IT

doctrine-query

全部标签

php - Doctrine 模型的默认排序属性

我想知道是否有办法为我的Doctrine模型声明默认顺序。例如我有一个工作模型,它有照片。当我加载一个作品时,所有与之关联的照片都会加载到$work->photos中。当我显示它们时,它们是按ID排序的。在另一个字段上声明默认顺序或者可能完全覆盖获取行为会非常方便。我不想将照片转换为数组并使用usort。谢谢。 最佳答案 您可以在YAML中指定如下:如果是表本身的某个字段的排序顺序添加:options:orderBy:fieldnameoptions:与columns:或relations:条目的深度相同。注意:orderBy:的大

php - Doctrine - 自引用实体 - 禁止获取 child

我有一个非常简单的实体(WpmMenu),它包含以自引用关系(称为邻接列表)相互连接的菜单项?所以在我的实体中我有:protected$idprotected$parent_idprotected$levelprotected$name所有getter/setter的关系是:/***@ORM\OneToMany(targetEntity="WpmMenu",mappedBy="parent")*/protected$children;/***@ORM\ManyToOne(targetEntity="WpmMenu",inversedBy="children",fetch="LAZY")

php - Symfony2 能否生成 :doctrine:entity generate entity with one-to-many relationship?

我想答案是否定的,但我想确定一下。SensioGeneratorBundle包含生成实体的命令。您知道它是否可以为one2Many或Many2Many字段生成映射吗?有没有实现这个的项目?我找到的唯一例子:phpapp/consoledoctrine:generate:entity--entity=AcmeBlogBundle:Blog/Post--format=annotation--fields="title:string(255)body:text"--with-repository--no-interaction非常感谢 最佳答案

php - 为什么列别名在 Doctrine 中不起作用?

我的脚本是这样的:$query=Doctrine_Query::create()->select('count(p.product_id)asnum_a')->from('ProductCommentsp')->groupBy('p.product_id')->having('num_a=2');生成的sql是:SELECTCOUNT(i.product_id)ASi__0FROMproductcommentsiGROUPBYi.product_idHAVINGnum_a=2因此执行sql时出现错误。我有两个问题:为什么表的别名是'i'而不是'p'?为什么having子句中的'num_

php - 如何使用 Doctrine2 中的级联选项让关联实体自动持久化?

谁能给我解释一下:$user=newUser();/*whydoIhavetocallEntityCommentwhiletryingtoinsertintodb?*/$myFirstComment=newComment();$user->addComment($myFirstComment);$em->persist($user);$em->persist($myFirstComment);$em->flush();为什么我在尝试插入数据库时​​必须调用EntityComment?我有级联。这是否意味着如果我在用户实体中与其他人有50个关系尝试时我必须手动调用每个关系的实体更新/插入

php - 如何在 Doctrine2 查询生成器中使用 'interval'

在我的Symfony2存储库中,我想从计划表中获取对象,这些对象已经开始但尚未完成。对象内的间隔应作为“未完成”遇到,应作为变量传递。使用纯SQL,它的工作原理如下:SELECT*FROMslotsrbsWHERErbs.rundate='2012-08-13'ANDrbs.runtime我可以使用DQL/QueryBuilder实现同样的目标吗?这是我目前所拥有的:$qb=$this->createQueryBuilder('rbs');$qb->where($qb->expr()->andX($qb->expr()->eq('rbs.rundate',':date'),$qb->e

php - Symfony2 命令 "doctrine:schema:update"未检测实体中使用的特征文件更改

我有一个特征文件,其中包含实体之间的共享代码。特征文件示例:status=$status;return$this;}publicfunctiongetStatus(){return$this->status;}publicfunctionsetDate($date){$this->date=$date;return$this;}publicfunctiongetDate(){return$this->date;}}实体文件示例:id;}publicfunctionsetGallery(\Application\Sonata\MediaBundle\Entity\Gallery$gall

php - Symfony2 - Doctrine 和 FOSUserBundle - 错误的注释

总的来说,我是Symfony2的新手。不过,这个问题与Doctrine和FOSUserBundle相关。我有以下基于FOSUserBundle和自引用多对多创建的User.php实体。hasAccessTo=new\Doctrine\Common\Collections\ArrayCollection();$this->hasAccessToMe=new\Doctrine\Common\Collections\ArrayCollection();}}尝试更新缓存或删除时出现以下错误:[Doctrine\Common\Annotations\AnnotationException][Se

php - Doctrine 2 : Arbitrary join and single table inheritance

注意:这是一个ORM限制reportedontheproject'sissuetracker我在使用Doctrine2.3中引入的任意连接语法在作为层次结构根的实体类上构建DQL查询时遇到问题。给定这些类:A-noinheritanceB1-abstract,rootofahierarchy,discriminatorcolumnisnamed'type'我像这样设置一个查询构建器:$qb->select('a.idASidA,b.idASidB')->from('\Entity\A','a')->leftJoin('\Entity\B1','b',\Doctrine\ORM\Quer

php - Doctrine 在 Google App Engine 上找不到数据?

当我做一个简单的查询时,比如查找所有用户,它返回一个空数组。$users=$em->getRepository('MyApp\\Model\\Entity\\User')->findAll();但是,当我使用PDO手动连接到我的数据库时,它找到了数据。我正在使用ArrayCache方法,以确保它与没有文件系统的GAE无关。GAE文档说您可以使用sys_get_temp_dir(),所以我认为这不是我的代理。我不明白为什么Doctrine什么都不返回也不抛出任何错误。这是我的应用的Bootstrap文件:addDriver($annotationDriver,'MyApp\\Model\