getRepository -> find using whereClause to filter multiEnum fields

Collapse
X
Collapse
+ More Options
Posts
 
  • Time
  • Show
Clear All
new posts
  • wtconseil
    Active Community Member
    • Apr 2015
    • 335

    getRepository -> find using whereClause to filter multiEnum fields

    Hi there

    I have a custom entity with a multiEnum field called "statut"
    i try to write a custom entrypoint to build a custom dashboard, adding some stuff to filter my dashboard

    I have tried many differents synthax but i don't manage to filter my data regarding "multiEnum" fields value.

    Here is my php code
    PHP Code:
    $whereClause = array();
    $whereClause['statut=*'] = 'Prospect';
    $order_by = "name";
    
    $searchParams = array(
    'whereClause' => $whereClause,
    'orderBy' => $order_by
    );
    
    $data = $this->getEntityManager()->getRepository('DossierMDB')->find($searchParams); 
    
    i tried many synthax about => $whereClause['statut=*'] = 'Prospect';
    $whereClause['statut'] = 'Prospect';

    or

    $whereClause[] = array('statut' => 'Prospect');

    or

    $whereClause[] = array('statut' => array('Prospect'));

    but didn't manage to get any filtered results

    any idea?

    Thanks for your support !

    I didn't find any documentation about the synthax available for the "keys" of that whereClause array :-(
    https://github.com/espocrm/documenta...lopment/orm.md
  • wtconseil
    Active Community Member
    • Apr 2015
    • 335

    #2
    After digging... i found this synthax that seems to work

    PHP Code:
    $whereClause[] = array('statut*' => '%' . $mdb_statut[$_GET['statut_index']] . '%'); 
    
    am i right?

    Comment

    • tanya
      Senior Member
      • Jun 2014
      • 4308

      #3
      Try to wrap Prospect in %

      Comment

      • wtconseil
        Active Community Member
        • Apr 2015
        • 335

        #4
        Yep, thanks !
        i found all the different synthax in application/Espo/Core/SelectManagers/Base.php
        switch case :-)

        Thanks !

        Comment

        • yuri
          Member
          • Mar 2014
          • 8511

          #5
          More info added at https://github.com/espocrm/documenta...lopment/orm.md
          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

          • wtconseil
            Active Community Member
            • Apr 2015
            • 335

            #6
            yuri
            Thanks that's perfect !!

            Another point: how do you escape value of a multiEnum list ? I have "'" and "/" in some values and it doesn't seem to work.
            I tried to addslashes / stripslashes but not working

            Ex: my field called "Stage" has these values => "A / B", "B'C", "C-D"

            Thanks for your support!

            Last edited by wtconseil; 02-12-2018, 02:22 PM.

            Comment

            • wtconseil
              Active Community Member
              • Apr 2015
              • 335

              #7
              tanya maybe an idea? thx

              Comment

              • tanya
                Senior Member
                • Jun 2014
                • 4308

                #8
                You have to escape \
                $whereClause['tesst*'] = "%A \\\\/ B%";

                Comment

                • wtconseil
                  Active Community Member
                  • Apr 2015
                  • 335

                  #9
                  Thanks !
                  $data = str_replace("/", "\\\\/", $data)

                  Comment

                  Working...