Select List with WHERE

Select List with WHERE

cemlimitedcemlimited Posts: 36Questions: 9Answers: 0
edited March 2022 in Select

When using a Join to populate a Select drop down in a table field from another table, Is it possible to submit a value to the controller to limit the items in the list?

I know the main table can be filtered using $aaa->where( '$table.$field', $target, '=');
but i also need the options to be filtered....

Something like adding 'WHERE user = $variable at the location shown with the ///// below

$table = Main Datatable Source
$table has two fields (field 1 & 4) in it corresponding to lists from 2 other tables (table1 and table4)

$selects = array('field1', 'field4');
$selectstable = array('table1', 'table4');
$selectslabels = array('field2', 'field5');

(field2 would be a value from table1 corresponding to field1)
(field5 would be a value from table2 corresponding to field4)

While table4 may have 15 items in it, I only want the items where possibly field 7 from table 4 is 0

foreach($selects as $select){
    $aaa ->field(Field::inst($table.'.'.$select)
                  ->options( Options::inst()->table( $selectstable[$cycle] )
                      ->value( 'id' )
                         ->label( $selectslabels[$cycle] ))
                         ->validator( Validate::dbValues()));
    $aaa ->field(Field::inst( $selectstable[$cycle].'.'.$selectslabels[$cycle]));
    $aaa ->leftJoin( $selectstable[$cycle],$selectstable[$cycle].'.id', '=', $table.'.'.$select//// );
    $cycle = $cycle + 1;
}

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    Answer ✓

    The Options class does have a where() method as well, but what it is currently lacking is a leftJoin method. So if you need the condition to be dependent on data from another column, what you would need to do is create a VIEW in your database that would do that join for you and you could then direct the Options class to query directly from that.

    Adding a join to the Options class is a feature request that does pop up fairly regularly. I'm going to be looking at doing that for the next major release of Editor.

    Allan

Sign In or Register to comment.