Searchbuilder SSP and or_where

Searchbuilder SSP and or_where

ECEGROUPEECEGROUPE Posts: 77Questions: 28Answers: 1
edited February 2023 in SearchBuilder

I have a problem with SSP and Searchbuilder :

i have set up my serverside script to select only some data of my table, so at the end of my serverside script i use a where and or_where condition like this (it work) :

->where( function ( $q ) {
     $q

        ->where('mydata1', 2021, '>=')
        ->or_where('mydata1', null);

        } )

BUT when i perferm a filter with searchuilber for exemple on the column name ( Name, equals, MyName) it show multiple row and not only the row where name equals MyName because the query send to server also add or_where('mydata1', null) to the request.

To sum up this with numbers :
- The request -> where('mydata1', 2021, '>=') show 4000 results
- The request -> or_where('mydata1', null); show 150 results
(so a total of 4150 results are displayed in my table)
- The request with searchbuilder where name equals Myname should show 1 results BUT it show 151 results because it also apply the or_where.

I hope to have been clear, how to fix this ? Thx for your answer / time :)

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin
    Answer ✓

    Try:

    ->where( function ( $q ) {
      $q->where( function ( $r ) {
        $r
          ->where('mydata1', 2021, '>=')
          ->or_where('mydata1', null);
      } );
    } )
    

    The Editor->where() method does not automatically do grouping (i.e. parenthesis) but the Query->where() method (the inner one in my above code) does. That should resolve the issue.

    If it doesn't, can you add ->debug(true) just before the ->process(...) call please and then show me the response from the server?

    Thanks,
    Allan

  • ECEGROUPEECEGROUPE Posts: 77Questions: 28Answers: 1
    edited February 2023

    Thank for the answer, it work :)

Sign In or Register to comment.