Count Records INCLUDING Marked For Deletion

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • blueprint
    Active Community Member
    • Jan 2019
    • 223

    Count Records INCLUDING Marked For Deletion

    I want to count the number of records created on a certain date, but this number MUST include those marked for deletion

    Code:
    $count = $this->getEntityManager()->getRepository($entityType)->where([
        'createdAt*' => date("Y-m-d %:%:%")
    ])->count();
    The above code only counts the non-deleted ones.

    How can I take into account those records which have been deleted?
  • item
    Active Community Member
    • Mar 2017
    • 1476

    #2
    Hello,
    by PDO
    a sample.. you need use select count
    PHP Code:
    $pdo = $this->getEntityManager()->getPDO();
            $sql = "DELETE FROM scheduled_job_log_record WHERE status='Success';DELETE FROM job WHERE status='Success'";
            $sth = $pdo->prepare($sql);
            $sth->execute(); 
    
    If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

    Comment

    • blueprint
      Active Community Member
      • Jan 2019
      • 223

      #3
      item nice one, thank you - I’ll try this tomorrow!

      Comment

      • yuri
        Member
        • Mar 2014
        • 8440

        #4
        This should work out:

        PHP Code:
        $count = $entityManager->where($clause)->count(['withDeleted' => true]); 
        
        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

        • blueprint
          Active Community Member
          • Jan 2019
          • 223

          #5
          Originally posted by yurikuzn
          This should work out:

          PHP Code:
          $count = $entityManager->where($clause)->count(['withDeleted' => true]); 
          
          yuri thank you - this looks like a nicer solution but its useful to know about both methods.

          Comment

          Working...