QueryBuilder Join child and grand child

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kyle
    Senior Member
    • May 2020
    • 143

    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



  • yuri
    Member
    • Mar 2014
    • 8806

    #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' 
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • Kyle
      Senior Member
      • May 2020
      • 143

      #3
      Thanks Yuri, that worked.

      Comment

      Working...