草庐IT

doctrine_registry

全部标签

php - 使用 Doctrine 中的类表继承从子表中删除行

我用两个模型做了一个非常基本的例子。"Singer"extendsfrom"Person"我正在使用classtableInheritance使用这两个模型:歌手模型长这样:namespacemodels;/***@Table(name="singers")*@entity*/classSingerextendsPerson{/**@column(type="string",nullable=false)*/protected$gender;}工作流程考虑这种情况。在数据库中我有这些行:人员表:id_person|name|type-----------------------1joh

php - 在 Doctrine2 中将字段聚合到获取的对象

编辑:进一步研究:看起来答案在于更改默认的Hydrator以进行定制。Doctrine2允许您通过将他的名字作为参数发送来更改它:$query->getResult('CustomHydrator');不要忘记先在您的config.yml文件中注册它:doctrine:orm:hydrators:CustomHydrator:\your\bundle\Hydrators\CustomHydrator我的博客和评论实体之间的关系是一对多的。1博客有N条评论在研究了如何在Doctrine2中为获取的对象添加额外字段后,我发现了AggregateFields,这是一篇好文章,但只是谈论从单个

mysql - 如何在 doctrine2 queryBuilder 中实现 ON ( ... OR ...) mysql 查询

我在MYSQL中有一个SQL查询:例如SELECTs.*FROMvplanning.citiesasc1INNERJOINvplanning.citiesasc2ON(c1.id=c2.area_id)INNERJOINvplanning.storagesassON(s.city_id=c2.idORs.city_id=c1.id)WHEREc1.id=109;在原则上我可以写这样的东西(来self的工作代码):$query=$em->getRepository('VplanningPageBundle:Storage')->createQueryBuilder('s')->inner

php - 优化 Doctrine 查询以防止额外查询

我正在构建一个有更新墙的系统,您只能在其中看到好友的帖子。此处的“friend”按一组两个用户分类,这两个用户各自将彼此添加到他们的friend列表中。好友关联由DoctrineManyToMany关联处理,非常简单,如下所示:用户.php//..otherdeclarations/***@varArrayCollection*@ORM\ManyToMany(targetEntity="User")*@ORM\JoinTable(name="user_friends")*/protected$friends;//..moreunrelatedstuff并在我的查询中获取用户friend

php - 设置相等运算符的 Doctrine 更新查询

我在根据语句设置值时遇到问题我想激活一个特定的uc并停用所有其他ucs。(uc.collection=:collectionId)应返回true或false,以便正确处理。查询生成器:$queryBuilder=$this->getEntityManager()->createQueryBuilder();$queryBuilder->update('TestBundle:UserCollection','uc')->set('uc.active','(uc.collection=:collectionId)')->where('uc.user=:userId');$queryBuil

php - DQL 与 JOIN Doctrine2 和 Symfony2

您好,我有两个表:产品和库存。他们有manyToOne关系,看起来是这样的:库存:+------------+--------------+------+-----+---------+----------------+|Field|Type|Null|Key|Default|Extra|+------------+--------------+------+-----+---------+----------------+|id|int(11)|NO|PRI|NULL|auto_increment||stock_name|varchar(255)|NO||NULL|||address

mysql - 如何在doctrine中进行复杂的SQL查询

我有2个表:用户和他们的积分。用户有字段:编号姓名点有字段:编号开始日期结束日期count_of_points用户ID所以有些用户可能有积分也可能没有积分。点数条目受时间间隔限制(从开始日期到结束日期),并包含用户在此间隔内拥有的点数。我需要显示此时按总点数排序的用户表(时间戳必须在开始日期和结束日期之间)并稍后在View中显示此总和值。如果用户没有积分,则此计数必须等于0。我有这样的东西:$qb=$this->getEntityManager()->getRepository('MyBundle:User')->createQueryBuilder('u');$qb->select(

php - 如何防止 EntityManager (Doctrine Association) 删除

我遇到了以下问题:我有一个与客户一对一、单向关联的实体查询:/***@varCustomer**@ORM\OneToOne(targetEntity="Customer",cascade={"persist"},fetch="EAGER")*@ORM\JoinColumn(name="Customer",referencedColumnName="id",onDelete="SETNULL",nullable=true)*/protected$customer;如果我通过数据库后端(PhpMyAdmin)删除客户,那么一切都很好:客户字段设置为空,但如果我使用EntityManager

mysql - Doctrine 想要 "ALTER TABLE coo_users CHANGE id id VARCHAR(255) NOT NULL;"但每次我更新模式时都想这样做

如果我执行bin/consoledoctrine:schema:update--force结果是:Updatingdatabaseschema...Databaseschemaupdatedsuccessfully!"1"querywasexecuted每次运行update命令时都会执行此操作。因此,使用bin/consoledoctrine:schema:validate我看到了:[Mapping]OK-Themappingfilesarecorrect.[Database]FAIL-Thedatabaseschemaisnotinsyncwiththecurrentmappingf

php - Symfony 中的 Doctrine\ORM\Mapping\MappingException

我得到的完整错误是:[Doctrine\ORM\Mapping\MappingException]Property"followed"in"BackendBundle\Entity\Following"wasalreadydeclared,butitmustbedeclaredonlyonce当我尝试在我的BackendBundle中创建实体时。我在MYSQL中有3个表“empresas”、“tecnicos”、“profesionistas”,下面是每个表的fkCREATETABLEfollowing(idint(255)notnullauto_increment,userint(2