Espo 5.9.4 problem with ORM - Select Manager

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jakub.skowron
    Junior Member
    • Jan 2020
    • 21

    Espo 5.9.4 problem with ORM - Select Manager

    Hi,

    I found a problem using orm. When I try to use select manager and join another table in response I don't get any columns from join expression.

    PHP Code:
    $entityManager = $this->getEntityManager();
            try {
                $test = $entityManager->getRepository('ProcessedDeclaration')
                    ->select(['id', 'name', 'date', 'wasteMass', 'servicedBy', 'route.status', 'account.servicedBy']) // if I skip this, I receive full ProcessedDeclaration object without joined tables columns
                    ->join([['Account', 'account', ['account.id:' => 'id']]])
                    ->join([['Route', 'route', ['route.id:' => 'route_id']]])
                    ->join([['WasteTransferCard', 'wtc', ['wtc.id:' => 'waste_transfer_card_id']]])
                    ->join([['Legal,', 'l', ['l.id:' => 'account.current_legal_id']]]) // tried to name columns in camel case and snake case, the same results
                    ->join([['Driver', 'd', ['d.id:' => 'route.driver_route_id']]])
                    ->where([
                         'AND' => [
                             'wasteMass>' => 0,
                             'status' => [
                                 "Processed"
                             ]
                         ]
                    ])
                    ->groupBy('id')
                    ->limit(0, 1)
                    ->find();
                var_dump($test->toArray());
            } catch (\Exception $e) {
                var_dump($e->getMessage());
            } 
    
  • yuri
    Member
    • Mar 2014
    • 8493

    #2
    Hi,

    Entity can receive only its defined attributes. Your variable $test is of Entity type.

    Your case is MUCH easier to handle in v6.0.

    In v5 you can't use Repository for your case.

    You need to use raw select params.

    PHP Code:
    
    $sql = $this->getEntityManager()->getQuery()->createSelectQuery('ProcessedDeclaration', $selectParams);
    
    $sth = $pdo->prepare($sql);
    $sth->execute(); 
    
    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

    • yuri
      Member
      • Mar 2014
      • 8493

      #3
      In v6.0:

      PHP Code:
      
      $selectQuery = $entityManager
          ->getQueryBuilder()
          ->select()
          ->from('SomeTable')
          ->select( ... )
          ->join( ... )
          ->build();
      
      $row = $entityManager
          ->getQueryExecutor()
          ->execute($selectQuery)
          ->fetch(); 
      
      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

      Working...