- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我得到一个奇怪的结果数组结构
这是我在 symfony 平台上的 DQL 查询和 php 代码:
$params = array();
$query = $this->getEntityManager()
->createQuery('
SELECT c1 as cat1, c2 as cat2, c3 as cat3, count(s.id) as tot
FROM Priatdru\PolyglotBundle\Entity\SearchQuery s
INNER JOIN ApplicationSonataClassificationBundle:Category c1 WITH s.category1 = c1.id
INNER JOIN ApplicationSonataClassificationBundle:Category c2 WITH s.category2 = c2.id
LEFT JOIN ApplicationSonataClassificationBundle:Category c3 WITH s.category3 = c3.id
WHERE s.sessionId != :session_id
AND (
(s.category1 = :category1 AND s.category2 IS NOT NULL)
OR s.category2 = :category1
OR s.category3 = :category1
)
GROUP BY cat1,cat2,cat3
ORDER BY tot ASC
');
$params['session_id'] = $session_id;
$params['category1'] = $category1;
$query->setParameters($params);
return $query->getResult();
变量转储:
array (size=10)
0 =>
array (size=1)
'cat1' =>
object(Application\Sonata\ClassificationBundle\Entity\Category)[1309]
protected 'id' => int 8755
...
private 'nameEn' => string 'French' (length=6)
private 'nameFr' => string 'Français' (length=9)
private 'nameIt' => string 'Francese' (length=8)
private 'nameDe' => string 'Französisch' (length=12)
private 'nameEs' => string 'Francés' (length=8)
private 'slugEn' => string 'french' (length=6)
private 'slugFr' => string 'francais' (length=8)
private 'slugIt' => string 'francese' (length=8)
private 'slugDe' => string 'franzosisch' (length=11)
private 'slugEs' => string 'frances' (length=7)
protected 'name' => string 'fr' (length=2)
protected 'slug' => string 'french' (length=6)
protected 'enabled' => boolean true
protected 'description' => string 'French' (length=6)
protected 'createdAt' =>
object(DateTime)[1306]
...
protected 'updatedAt' =>
object(DateTime)[1307]
...
protected 'position' => null
protected 'children' =>
object(Doctrine\ORM\PersistentCollection)[1464]
...
protected 'parent' =>
object(Proxies\__CG__\Application\Sonata\ClassificationBundle\Entity\Category)[1540]
...
protected 'media' => null
protected 'context' =>
object(Proxies\__CG__\Application\Sonata\ClassificationBundle\Entity\Context)[1518]
...
1 =>
array (size=1)
'cat2' =>
object(Application\Sonata\ClassificationBundle\Entity\Category)[2390]
protected 'id' => int 8821
...
private 'nameEn' => string 'Italian' (length=7)
private 'nameFr' => string 'Italien' (length=7)
private 'nameIt' => string 'Italiano' (length=8)
private 'nameDe' => string 'Italienisch' (length=11)
private 'nameEs' => string 'Italiano' (length=8)
private 'slugEn' => string 'italian' (length=7)
private 'slugFr' => string 'italien' (length=7)
private 'slugIt' => string 'italiano' (length=8)
private 'slugDe' => string 'italienisch' (length=11)
private 'slugEs' => string 'italiano' (length=8)
protected 'name' => string 'it' (length=2)
protected 'slug' => string 'italian' (length=7)
protected 'enabled' => boolean true
protected 'description' => string 'Italian' (length=7)
protected 'createdAt' =>
object(DateTime)[2312]
...
protected 'updatedAt' =>
object(DateTime)[2396]
...
protected 'position' => null
protected 'children' =>
object(Doctrine\ORM\PersistentCollection)[2376]
...
protected 'parent' =>
object(Proxies\__CG__\Application\Sonata\ClassificationBundle\Entity\Category)[1540]
...
protected 'media' => null
protected 'context' =>
object(Proxies\__CG__\Application\Sonata\ClassificationBundle\Entity\Context)[1518]
...
2 =>
array (size=2)
'cat3' => null
'tot' => string '2' (length=1)
3 =>
array (size=1)
'cat1' =>
object(Application\Sonata\ClassificationBundle\Entity\Category)[2390]
protected 'id' => int 8821
...
private 'nameEn' => string 'Italian' (length=7)
private 'nameFr' => string 'Italien' (length=7)
private 'nameIt' => string 'Italiano' (length=8)
private 'nameDe' => string 'Italienisch' (length=11)
private 'nameEs' => string 'Italiano' (length=8)
private 'slugEn' => string 'italian' (length=7)
private 'slugFr' => string 'italien' (length=7)
private 'slugIt' => string 'italiano' (length=8)
private 'slugDe' => string 'italienisch' (length=11)
private 'slugEs' => string 'italiano' (length=8)
protected 'name' => string 'it' (length=2)
protected 'slug' => string 'italian' (length=7)
protected 'enabled' => boolean true
protected 'description' => string 'Italian' (length=7)
protected 'createdAt' =>
object(DateTime)[2312]
...
protected 'updatedAt' =>
object(DateTime)[2396]
...
protected 'position' => null
protected 'children' =>
object(Doctrine\ORM\PersistentCollection)[2376]
...
protected 'parent' =>
object(Proxies\__CG__\Application\Sonata\ClassificationBundle\Entity\Category)[1540]
...
protected 'media' => null
protected 'context' =>
object(Proxies\__CG__\Application\Sonata\ClassificationBundle\Entity\Context)[1518]
...
4 =>
array (size=1)
'cat2' =>
object(Application\Sonata\ClassificationBundle\Entity\Category)[1309]
protected 'id' => int 8755
...
private 'nameEn' => string 'French' (length=6)
private 'nameFr' => string 'Français' (length=9)
private 'nameIt' => string 'Francese' (length=8)
private 'nameDe' => string 'Französisch' (length=12)
private 'nameEs' => string 'Francés' (length=8)
private 'slugEn' => string 'french' (length=6)
private 'slugFr' => string 'francais' (length=8)
private 'slugIt' => string 'francese' (length=8)
private 'slugDe' => string 'franzosisch' (length=11)
private 'slugEs' => string 'frances' (length=7)
protected 'name' => string 'fr' (length=2)
protected 'slug' => string 'french' (length=6)
protected 'enabled' => boolean true
protected 'description' => string 'French' (length=6)
protected 'createdAt' =>
object(DateTime)[1306]
...
protected 'updatedAt' =>
object(DateTime)[1307]
...
protected 'position' => null
protected 'children' =>
object(Doctrine\ORM\PersistentCollection)[1464]
...
protected 'parent' =>
object(Proxies\__CG__\Application\Sonata\ClassificationBundle\Entity\Category)[1540]
...
protected 'media' => null
protected 'context' =>
object(Proxies\__CG__\Application\Sonata\ClassificationBundle\Entity\Context)[1518]
...
5 =>
array (size=2)
'cat3' => null
'tot' => string '5' (length=1)
6 =>
array (size=1)
'cat2' =>
object(Application\Sonata\ClassificationBundle\Entity\Category)[2397]
protected 'id' => int 8736
...
private 'nameEn' => string 'Spanish' (length=7)
private 'nameFr' => string 'Espagnol' (length=8)
private 'nameIt' => string 'Spagnolo' (length=8)
private 'nameDe' => string 'Spanisch' (length=8)
private 'nameEs' => string 'Español' (length=8)
private 'slugEn' => string 'spanish' (length=7)
private 'slugFr' => string 'espagnol' (length=8)
private 'slugIt' => string 'spagnolo' (length=8)
private 'slugDe' => string 'spanisch' (length=8)
private 'slugEs' => string 'espanol' (length=7)
protected 'name' => string 'es' (length=2)
protected 'slug' => string 'spanish' (length=7)
protected 'enabled' => boolean true
protected 'description' => string 'Spanish' (length=7)
protected 'createdAt' =>
object(DateTime)[2335]
...
protected 'updatedAt' =>
object(DateTime)[2330]
...
protected 'position' => null
protected 'children' =>
object(Doctrine\ORM\PersistentCollection)[2370]
...
protected 'parent' =>
object(Proxies\__CG__\Application\Sonata\ClassificationBundle\Entity\Category)[1540]
...
protected 'media' => null
protected 'context' =>
object(Proxies\__CG__\Application\Sonata\ClassificationBundle\Entity\Context)[1518]
...
7 =>
array (size=2)
'cat3' => null
'tot' => string '5' (length=1)
8 =>
array (size=1)
'cat1' =>
object(Proxies\__CG__\Application\Sonata\ClassificationBundle\Entity\Category)[1671]
public '__initializer__' => null
public '__cloner__' => null
public '__isInitialized__' => boolean true
protected 'id' => int 8616
...
private 'nameEn' (Application\Sonata\ClassificationBundle\Entity\Category) => string 'English' (length=7)
private 'nameFr' (Application\Sonata\ClassificationBundle\Entity\Category) => string 'Anglais' (length=7)
private 'nameIt' (Application\Sonata\ClassificationBundle\Entity\Category) => string 'Inglese' (length=7)
private 'nameDe' (Application\Sonata\ClassificationBundle\Entity\Category) => string 'Englisch' (length=8)
private 'nameEs' (Application\Sonata\ClassificationBundle\Entity\Category) => string 'Inglés' (length=7)
private 'slugEn' (Application\Sonata\ClassificationBundle\Entity\Category) => string 'english' (length=7)
private 'slugFr' (Application\Sonata\ClassificationBundle\Entity\Category) => string 'anglais' (length=7)
private 'slugIt' (Application\Sonata\ClassificationBundle\Entity\Category) => string 'inglese' (length=7)
private 'slugDe' (Application\Sonata\ClassificationBundle\Entity\Category) => string 'englisch' (length=8)
private 'slugEs' (Application\Sonata\ClassificationBundle\Entity\Category) => string 'ingles' (length=6)
protected 'name' => string 'en' (length=2)
protected 'slug' => string 'english' (length=7)
protected 'enabled' => boolean true
protected 'description' => string 'English' (length=7)
protected 'createdAt' =>
object(DateTime)[2394]
...
protected 'updatedAt' =>
object(DateTime)[2399]
...
protected 'position' => null
protected 'children' =>
object(Doctrine\ORM\PersistentCollection)[2326]
...
protected 'parent' =>
object(Proxies\__CG__\Application\Sonata\ClassificationBundle\Entity\Category)[1540]
...
protected 'media' => null
protected 'context' =>
object(Proxies\__CG__\Application\Sonata\ClassificationBundle\Entity\Context)[1518]
...
9 =>
array (size=2)
'cat3' => null
'tot' => string '17' (length=2)
当我更改 DQL 查询中的选择行时:
SELECT c1.name as cat1, c2.name as cat2, c3.name as cat3, count(s.id) as tot
现在结构数组是我所期望的:变量转储:
array (size=4)
0 =>
array (size=4)
'cat1' => string 'fr' (length=2)
'cat2' => string 'it' (length=2)
'cat3' => null
'tot' => string '2' (length=1)
1 =>
array (size=4)
'cat1' => string 'fr' (length=2)
'cat2' => string 'es' (length=2)
'cat3' => null
'tot' => string '5' (length=1)
2 =>
array (size=4)
'cat1' => string 'it' (length=2)
'cat2' => string 'fr' (length=2)
'cat3' => null
'tot' => string '5' (length=1)
3 =>
array (size=4)
'cat1' => string 'en' (length=2)
'cat2' => string 'fr' (length=2)
'cat3' => null
'tot' => string '17' (length=2)
如果有人遇到过类似问题,请分享信息。提前感谢所有社区!问候
最佳答案
我希望我能帮你解决一些问题。
在第一个示例中,您的 DQL 查询与实体一起工作:
SELECT c1 as cat1, c2 as cat2, c3 as cat3
正如您在 c1 as cat1 中看到的那样,计算的结果集将是 ApplicationSonataClassificationBundle:Category 类型,当然,所有其他连接关系也将出现。出于所有意图和目的,您在这里处理对象。
在您提供的第二个示例中:
SELECT c1.name as cat1, c2.name as cat2, c3.name as cat3, count(s.id) as tot
如您所见,您正在使用实体字段 (c1.name),对结果强制执行 ArrayHydration。
如果您想保持第一种方法,请确保适当补水:
$query = $em->createQuery('SELECT u FROM CmsUser u');
$users = $query->getResult(Query::HYDRATE_ARRAY);
进一步引用检查this page.
编辑:
在这种情况下,您正在进行非常具体的提取,通常的做法是完全放弃对象关系并转向数组方法。您可以使用第二个示例中所述的更具体的 select 1.name;
如果需要检索对象,您可以考虑将标识符添加到提取 c1.id 并lazly 从存储库 (findBy) 中获取它。
希望对你有帮助
问候。
关于php - 奇怪的学说结果数组结构如果我在 DQL 查询中传递三次与相同的相关实体连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30307767/
我几乎尝试了所有方法来尝试创建代表我的数据库架构的实体,但仍然存在整页错误。如果有人能给我一些启发,我将不胜感激。 基本上我们有两份注册表,一份用于品牌,一份用于影响者。在每个表单中,我们都会要求您提
我有关于双向 OneToMany ManyToOne 的问题我的实体之间的关系 Device和 Event .这是映射的样子: // Device entity /** * @OR
我有一些具有一对多/多对一关系的实体 - 生产类- /** * @OneToMany(targetEntity="ProductionsKeywords", mappedBy="production
我正在使用 symfony 2.3 和 doctrine 2.2。我创建了一个控制台命令,以便在数据库中插入一些数据。当我尝试用当前日期更新时间列时,我收到此错误 Catchable fata
我想用 limit 做一个 fetchAll() 吗?您知道 symfony2 的实体管理器是否可行吗? 我当前的代码(获取所有,无限制): $repository = $this->getDoctr
客户需要根据需要更改项目的顺序,这意味着我需要一些“顺序”或“顺序”列来保存每个项目的实际位置。 如何使用 Doctrine 2 来实现这一点? 最佳答案 我会使用 Doctrine 的 event
在 Symfony2/Doctrine 中插入记录后触发事件的最佳方法是什么? 最佳答案 首先,将服务注册为 Doctrine 事件监听器: app/config.yml: services:
我很难让这个doctrine2扩展发挥作用。是https://github.com/djlambert/doctrine2-spatial关于如何创建多边形的文档并不多。我已经让配置文件正常工作了,但
我正在尝试对我的 FacebookEventResult 实体执行 native 查询,并创建与我的 FacebookEvent 实体的连接。 FacebookEventResult中的相关映射: /
我使用 SyliusSandbox 包开发商店。Sylius 使用 xml 文件来存储实体的 ORM 模式。 我已经将它的 xml 定义复制到我的 Bundle 中并在那里使用它。 但对于我自己的
客户需要根据需要更改项目的顺序,这意味着我需要一些“顺序”或“顺序”列来保存每个项目的实际位置。 如何使用 Doctrine 2 来实现这一点? 最佳答案 我会使用 Doctrine 的 event
我有以下查询: $em = $this->getEntityManager(); $query = $em->createQueryBuilder()->select('shopp
我定义了两个数据库实体 项目: use Doctrine\ORM\Mapping as ORM; use \Kdyby\Doctrine\Entities\MagicAccessors; /** *
我想要的是得到产品,产品应该是这样的: { idProduct: 1, mainCategory: 1, // One of the categories is the main one.
我使用以下查询: SELECT u.username, u.password, s.name, s.price FROM AcmeBundle:User u LEFT JOIN AcmeBundle:
我做了一些研究来回答它,但我没有找到。 我想知道在以下之间进行选择(加入)的最佳做法是什么: 使用查询生成器? $this->getEntityManager()->createQueryBuilde
我对原则 2 有疑问。我有以下数据库表:因此,Doctrine 生成从站点的桌面设置中检索数据的实体,但我需要从 desk_settings 表中检索所有设置并使用 desk_id 从 desk_se
我有两个实体,用户和客户端,一个客户端可以有很多用户。 通常我想要一个用户实体并延迟加载客户端,但由于某些原因,当我尝试访问其属性时,客户端代理不会自行加载。 如果我像这样转储数据 \Doctrine
我在验证方面遇到问题。在 Doctrine 1 中,我使用了这个: if ($model->isValid()) { $model->save(); } else { $errorSt
我将以下实体映射到 Doctrine 2 : class Zone { /** * @ManyToOne(targetEntity="Zone", inversedBy="child
我是一名优秀的程序员,十分优秀!