Cascading Dropdown question for multiple requirements

Cascading Dropdown question for multiple requirements

rob1strob1st Posts: 84Questions: 22Answers: 0
edited November 2021 in Editor

Hopefully an easy question.

I user editor dependant for a cascading dropdown and all working ok, code in the AJAX is:

->select( 'cxprocedure', ['id as value', 'CONCAT(procedureTag, " - ", procedureName) as label'], ['system1' => $_REQUEST['values']['subsystem'], 'procedureType' => 3])
    ->fetchAll();

I want to make it so that the cascading dropdown looks at system1 AND system2 and provides all relevant options that match either (so an OR requirement).

I tried

->select( 'cxprocedure', ['id as value', 'CONCAT(procedureTag, " - ", procedureName) as label'], ['system1' => $_REQUEST['values']['subsystem'], 'procedureType' => 3] || ['system2' => $_REQUEST['values']['subsystem'], 'procedureType' => 3]])
    ->fetchAll();

but it didn't like that, any idea how I can do this?

Thanks in advance.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    The where condition can be provided as a function so this should do it:

    ->select(
        'cxprocedure',
        [
            'id as value',
            'CONCAT(procedureTag, " - ", procedureName) as label'
        ],
        function ($q) {
            $q
                ->where("procedureType", 3)
                ->where(function ($r) {
                    $r->where('system1', $_REQUEST['values']['subsystem']);
                    $r->where('system2', $_REQUEST['values']['subsystem']);
                });
        }
    )
    ->fetchAll();
    

    Allan

  • rob1strob1st Posts: 84Questions: 22Answers: 0

    Awesome, thank you Allan

  • rob1strob1st Posts: 84Questions: 22Answers: 0

    Just to help others make sure you add or_where to the second where in the function. :)

Sign In or Register to comment.