有没有可能用Doctrine得到数组的数组?
在本例中,我希望country应该是一个数组。
$user['country']['name']
or
$user['country']['cid']我现在的要求是:
$query = $this->createQueryBuilder('u')
->select('u')
->getQuery();
return $query->getResult(\Doctrine\ORM\Query::HYDRATE_ARRAY);我这里只有身份证。
带有yml的教义实体:
用户:
TestBundle\Entity\User:
type: entity
table: user
repositoryClass: TestBundle\Entity\UserRepository
id:
uid:
type: integer
nullable: false
unsigned: true
id: true
generator:
strategy: IDENTITY
fields:
firstname:
type: string
nullable: true
length: 255
fixed: false
lastname:
type: string
nullable: true
length: 255
fixed: false
email:
type: string
nullable: true
length: 255
fixed: false
oneToOne:
country:
targetEntity: Country
joinColumn:
name: country
referencedColumnName: cid
lifecycleCallbacks: { }国家/地区:
TestBundle\Entity\Country:
type: entity
table: country
repositoryClass: TestBundle\Entity\CountryRepository
id:
cid:
type: integer
nullable: false
unsigned: false
id: true
generator:
strategy: IDENTITY
fields:
cid:
type: integer
nullable: true
unsigned: false
options:
default: 0
name:
type: string
nullable: true
length: 255
fixed: false
lifecycleCallbacks: { }这取决于我的例子中的速度,因为我有大约10000个对象。
另一种解决方案是,编写一条带有大量“join”的SQL语句,因为上面的例子只是一个简短的例子,我有大约7个这样的列,比如"group“等等。
发布于 2016-08-14 03:40:40
您可以简单地使用对象,而不是使数组水合。然后,您可以通过应该在模型类中定义的getter来访问Country属性。如果你确实需要一个数组,你可以使用php来填充它们。
但是如果你真的需要速度,你实际上应该考虑使用一个原始的select语句,它可以被优化得比Doctrine可能做的要好得多,不管复杂性如何。
https://stackoverflow.com/questions/38877513
复制相似问题