草庐IT

doctrine

全部标签

php - Symfony + Doctrine 与链接表的多对多关系

情况:我有3个表:Student、Address、StudentAddressLink如下注意*不是确切的yaml文件,但你明白了Student:column:id:blahblahname:blahblahAddress:column:id:~street:~StudentAddressLink:column:id:~student_id:~address_id:~relations:Student:local:student_idforeign:idAddress:local:address_idforeign:id我想从Student对象获取相关的“AddressStreet”目

php - 判断一个实体是否存在于 Doctrine 2 中的最有效方法

我正在创建注册表单并想检查电子邮件是否尚未与帐户相关联。我能看到的所有方法都将创建整个用户实体,但我只需要知道它是否存在。 最佳答案 publicfunctionisUnusedEmail($email){$em=static::$pimple['em'];$dql='SELECT1FROMApp\Model\UseruserWHEREuser.email=:email';$query=$em->createQuery($dql);$query->setParameter('email',$email);$res=$query->g

php - 运行 "No such file or directory"时的故障排除 `php app/console doctrine:schema:create`

我是Symfony2(beta4)和Doctrine的新手,当我尝试通过命令行创建数据库架构时遇到问题。这是错误:$phpapp/consoledoctrine:schema:createCreatingdatabaseschema...[PDOException]SQLSTATE[HY000][2002]Nosuchfileordirectory[ErrorException]Warning:PDO::__construct():[2002]Nosuchfileordirectory(tryingtoconnectviaunix:///var/mysql/mysql.sock)in/

php - 运行 "No such file or directory"时的故障排除 `php app/console doctrine:schema:create`

我是Symfony2(beta4)和Doctrine的新手,当我尝试通过命令行创建数据库架构时遇到问题。这是错误:$phpapp/consoledoctrine:schema:createCreatingdatabaseschema...[PDOException]SQLSTATE[HY000][2002]Nosuchfileordirectory[ErrorException]Warning:PDO::__construct():[2002]Nosuchfileordirectory(tryingtoconnectviaunix:///var/mysql/mysql.sock)in/

php - 使用 PHP Doctrine ORM 的复杂 WHERE 子句

我正在使用PHPDoctrineORM来构建我的查询。但是,我似乎不太明白如何使用DQL(DoctrineQueryLanguage)编写以下WHERE子句:WHEREname='ABC'AND(category1='X'ORcategory2='X'ORcategory3='X')ANDprice>10如何指定括号的位置?我目前的PHP代码是这样的:->where('name=?','ABC')->andWhere('category1=?','X')->orWhere('category2=?','X')->orWhere('category3=?','X')->andWhere(

php - 使用 PHP Doctrine ORM 的复杂 WHERE 子句

我正在使用PHPDoctrineORM来构建我的查询。但是,我似乎不太明白如何使用DQL(DoctrineQueryLanguage)编写以下WHERE子句:WHEREname='ABC'AND(category1='X'ORcategory2='X'ORcategory3='X')ANDprice>10如何指定括号的位置?我目前的PHP代码是这样的:->where('name=?','ABC')->andWhere('category1=?','X')->orWhere('category2=?','X')->orWhere('category3=?','X')->andWhere(

php - Doctrine2 加入 SUM

我正在尝试找出在Doctrine2中执行此操作的最佳方法。我有帐户实体,其中有一对多到交易实体。我需要对按帐户过滤的交易中的所有值求和。在SQL中是这样的:SELECTa.*,SUM(t.amount)ASbalanceFROMaccountaINNERJOINtransactiontONt.account_id=a.id方法#1:直接在实体上classAccount{//someotherdefinitions/***@OneToMany(targetEntity="Transaction",mappedBy="account")*/private$transactions;publ

php - 为什么我不能在 Doctrine 实体中使用公共(public)属性?

假设我有一个非常简单的PHPCRUD系统来管理数据库。假设它包含一个产品列表。使用DoctrineORM,我想查询数据库并查看/编辑/添加记录。根据GettingStarted手册,Whencreatingentityclasses,allofthefieldsshouldbeprotectedorprivate(notpublic),withgetterandsettermethodsforeachone(except$id).TheuseofmutatorsallowsDoctrinetohookintocallswhichmanipulatetheentitiesinwaysth

php - 如何处理 doctrine2 数据 fixture (平面文件)

我正在研究doctrine2以及如何处理数据固定装置。我对从平面文件(csv、yaml、xls)中读取它们特别感兴趣。在doctrine1.2中,数据固定装置是这样处理的:http://www.doctrine-project.org/projects/orm/1.2/docs/manual/data-fixtures/en#data-fixtures关于如何在doctrine2中处理这个问题有什么建议吗? 最佳答案 正如Steven已经提到的,fixture-feature作为一个单独的repo提供。我花了一些时间来弄清楚如何在S

php - Doctrine ODM MongoDB - 复制带有约束的简单一对多引用

我是Doctrine、mongo和ODM设置的新手,在ZF1中使用此设置时,我试图复制一个简单的一对多引用并带有约束。这是情况,希望就如何实现这一点提出一些建议。这是一个简单的用户->角色映射,所以在sql情况下我会有如下表:Users-id-name-role_idRoles-id-name然后将在用户role_id上设置外键约束以映射到角色id。删除角色后,将触发外键约束以停止操作。如何在DoctrinesMongoDBODM中实现相同的目标?到目前为止,我已经在User实体上使用了不同类型的注释,包括具有不同级联选项的@ReferenceOne@ReferenceMany...现