Announcement

Collapse
No announcement yet.

QueryBuilder Join child and grand child

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • QueryBuilder Join child and grand child

    Hi,

    I have a parent > child > grand child relationship that I want to query and get data from all 3 tables

    I have been trying to do this with QueryBuilder but have not had any luck, I can not work out how to get the grandchild data

    PHP Code:
            $selectJobGroup $this->getEntityManager()
            ->
    getQueryBuilder()
            ->
    select()
            ->
    from('Parent')
            ->
    join('Child''c')
            ->
    leftJoin('GrandChild''gc', ['c.grandChildId' => 'gc.id']) // is not correct!!
            
    ->select(['id''status''createdAt''c.status''gc.name'])
            ->
    build(); 
    I do not know how to base my join to the GrandChild off the Child record. gc.name is always null

    Any help would be appreciated




  • #2
    Use the colon character to indicate that the right part is an expression (by default it's treated as a value).

    PHP Code:
    'c.grandChildId:' => 'gc.id' 

    Comment


    • #3
      Thanks Yuri, that worked.

      Comment

      Working...
      X