Announcement

Collapse
No announcement yet.

Not 'where' clause ORM

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

  • 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 

  • #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(); 

    Comment


    • #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


      • #4
        No. It's single entity object.

        Comment


        • #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


          • #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


            • #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...
              X