Doctrine PHPCR-ODM Query Builder选择特定节点内的文档

时间:2014-05-01 11:20:29

标签: symfony doctrine query-builder doctrine-odm symfony-cmf

我有以下节点:

/
/applications
/applications/1
/applications/1/pages [contains Page documents]

我想选择节点Page内的所有/applications/1个文档。我使用以下方法来做到这一点(看似正确),但它会引发错误:

$qb = $this->dm->createQueryBuilder();
$qb->from()->document('Mango\CoreDomainBundle\Document\Page', 'page');

// I want to select the pages which are a child of /applications/1
$qb->where()->child('/applications/1', 'application');

$qb->getQuery()->execute();

执行此操作时,会抛出以下错误:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'n1.id' in 'field list'

这是发送回数据库的SQL查询:

SELECT 
    n0.id AS n0_id,
    n0.path AS n0_path,
    n0.parent AS n0_parent,
    n0.local_name AS n0_local_name,
    n0.namespace AS n0_namespace,
    n0.workspace_name AS n0_workspace_name,
    n0.identifier AS n0_identifier,
    n0.type AS n0_type,
    n0.props AS n0_props,
    n0.depth AS n0_depth,
    n0.sort_order AS n0_sort_order,
    n1.id AS n1_id,
    n1.path AS n1_path,
    n1.parent AS n1_parent,
    n1.local_name AS n1_local_name,
    n1.namespace AS n1_namespace,
    n1.workspace_name AS n1_workspace_name,
    n1.identifier AS n1_identifier,
    n1.type AS n1_type,
    n1.props AS n1_props,
    n1.depth AS n1_depth,
    n1.sort_order AS n1_sort_order
FROM
    phpcr_nodes n0
WHERE
    n0.workspace_name = 'mango'
        AND n0.type IN ('nt:unstructured' , 'rep:root')
        AND (n1.parent = 'applications/1'
        AND (EXTRACTVALUE(n0.props,
            'count(//sv:property[@sv:name="phpcr:class"]/sv:value[text()="Mango\CoreDomainBundle\Document\Page"]) > 0')
        OR EXTRACTVALUE(n0.props,
            'count(//sv:property[@sv:name="phpcr:classparents"]/sv:value[text()="Mango\CoreDomainBundle\Document\Page"]) > 0')))

我希望有人可以帮助我!谢谢!

1 个答案:

答案 0 :(得分:0)

嗯,看起来我只是愚蠢:P用作子条件的第二个参数的别名必须是运行查询构建器的文档的别名。

错:

$qb = $this->dm->getRepository('Mango\CoreDomainBundle\Document\Page')
    ->createQueryBuilder('page');
$qb->where()->child('/applications/456', 'alias_1');

$qb = $this->dm->getRepository('Mango\CoreDomainBundle\Document\Page')
    ->createQueryBuilder('page');
$qb->where()->child('/applications/456', 'page');

另外,就我而言,我必须使用descendant而不是child。见http://docs.doctrine-project.org/projects/doctrine-phpcr-odm/en/latest/reference/query-builder-reference.html#descendant

可以关闭主题:)