Question

I have the following nodes:

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

I want to select all Page documents inside the node /applications/1. I used the following to do that (which seems right), but it throws an error:

$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();

When I execute this, it throws the following error:

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

This is the SQL query that is send back to the database:

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')))

I hope somebody can help me out! Thanks!

Was it helpful?

Solution

Hmm, it looks like I was just dumb :P The alias used as the second argument of the child condition has to be the alias of the document you run the query builder on.

Wrong:

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

Good

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

Also, in my case, I had to use descendant rather than child. See http://docs.doctrine-project.org/projects/doctrine-phpcr-odm/en/latest/reference/query-builder-reference.html#descendant

Topic can be closed :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top