Announcement

Collapse
No announcement yet.

QueryBuilder not defined

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

  • QueryBuilder not defined

    Hello,
    please, can you help with QueryBuilder and Complex expressions​

    I need to use Complex expressions​ in my custom controller. I always use entityManager to create queries, but now it's easier to use ComplexExpression.
    I follow the example from docs: https://docs.espocrm.com/development...ex-expressions but everytime I got a warning with error.

    So the issue is here

    [2023-01-31 14:13:10] WARNING: E_WARNING: Undefined property: Espo\Custom\Controllers\StockManager::$queryBuilde r {"code":2,"message":"Undefined property: Espo\\Custom\\Controllers\\StockManager::$queryBui lder","file":"/var/www/html/custom/Espo/Custom/Controllers/StockManager.php","line":315} []

    [2023-01-31 14:13:10] ERROR: Slim Application Error Type: Error Code: 0 Message: Call to a member function where() on null File: /var/www/html/custom/Espo/Custom/Controllers/StockManager.php Line: 315



    And here is my controller code:

    Code:
    <?php
    
    namespace Espo\Custom\Controllers;
    
    use Espo\ORM\Entity;
    use Espo\ORM\EntityManager;
    use Espo\Core\Api\Request;
    
    use Espo\ORM\Query\SelectBuilder as QueryBuilder;
    use Espo\ORM\Query\Part\Condition as Cond;
    use Espo\ORM\Query\Part\Expression as Expr;
    
    class StockManager extends \Espo\Core\Templates\Controllers\BasePlus
    {
    
    public function postActionCreateQuoteForSupplier(Request $request) : bool{
    ​
    //this is copy of code from docs
    $StockManagerProducts = $queryBuilder->where(Expr::greater(Expr::column('StockManager.orderedQty'),100));
    
    
    }
    
    }

    where I'm wrong, can you help me?









  • #2
    Hi,

    In the docs above you can see that query builder can be obtained from the entity manager: $entityManager->getQueryBuilder(). You can pass the entity manager to any class via constructor: https://docs.espocrm.com/development...entity-manager

    Comment

    Working...
    X