Not 'where' clause ORM

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • worldmiros
    Senior Member
    • Dec 2015
    • 120

    Not 'where' clause ORM

    If I want to find an entity where the column is not equal to such value, how would I do it?
    PHP Code:
    $entity = $this->getEntityManager()->getRepository('EntityName')->where(array(
      'columnName!=' => $value
    ))->find();
    
    or 
    
    $entity = $this->getEntityManager()->getRepository('EntityName')->where(array(
      'columnName<>' => $value
    ))->find();
    
    or something else 
    
  • yuri
    Member
    • Mar 2014
    • 8485

    #2
    First one is correct. With fix:

    PHP Code:
    $entityList = $this->getEntityManager()->getRepository('EntityName')->where(array(
      'columnName!=' => $value
    ))->find();
    
    $entity = $this->getEntityManager()->getRepository('EntityName')->where(array(
      'columnName!=' => $value
    ))->findOne(); 
    
    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

    • worldmiros
      Senior Member
      • Dec 2015
      • 120

      #3
      May be a dumb question, but for getRepository('EntityName')->where(array( 'columName' => $value))->find(), if one is found, is it still an array?

      Comment

      • yuri
        Member
        • Mar 2014
        • 8485

        #4
        No. It's single entity object.
        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

        • worldmiros
          Senior Member
          • Dec 2015
          • 120

          #5
          I want to get a list of certain rows based on a column match. Am I doing something wrong with the code below?
          PHP Code:
          $entity = $this->getEntityManager()->getRepository('EntityName')->where(array(
            'columnName' => $value
          ))->find();
          
          $bool = false;
          foreach($entity as $ent){
           if($ent->columnName != $value){
                  $bool = true;
            }
          }
          
          if($bool){
           //do something
          } 
          
          Last edited by worldmiros; 08-04-2016, 03:01 PM. Reason: adding more code

          Comment

          • worldmiros
            Senior Member
            • Dec 2015
            • 120

            #6
            I'm in espo/core/utils/auth.php directory. If I wanted a list from the db based on a few column/row value, is the code below correct?
            PHP Code:
            $entity = $this->getEntityManager()->getRepository('EntityName')->where(array(
              'columnName' => $value,
             'columnName2' => $value2
            ))->find();
            
            $bool = false;
            foreach($entity as $ent){
             if($ent->columnName != $value){
                    $bool = true;
              }
            }
            
            if($bool){
             //do something
            } 
            

            Comment

            • worldmiros
              Senior Member
              • Dec 2015
              • 120

              #7
              I was able to fix my issue. It's not pretty but resolved.
              PHP Code:
              $entity = $this->getEntityManager()->getRepository('EntityName')->where(array(
               'columnName' => $value
              ))->find();
              
              //changed it to array to access it values by associative
              
              $entity = $entity->toArray();
              foreach($entity as $ent){
               $obj = $ent['columnName'];
              } 
              
              I don't want to access the column name by converting it to array all the time. Still would like to know how to trickle down the list without converting it to an array.

              Comment

              Working...