Where clause in search panes
Where clause in search panes
Khalid Teli
Posts: 251Questions: 71Answers: 0
Hi ,
I am trying to write a where clause for searchPane option like this
Field::inst('returns.member','member')
->searchPaneOptions( SearchPaneOptions::inst()
->table( 'returns' )
->value( 'id' )
->label( 'member' )
->where( function ($q) {
$q->where( 'member', 'ab foods' );
})
)
it works fine but it returns all the instances of member from table (SELECT member from returns where member = 'ab foods').
However, in the ideal case it should only return one instance (sql should be like SELECT DISTINCT member from returns where member = 'ab foods'
)
Thank you
KT
Answers
You can use a closure function for the options as well. That supports executing your own SQL-statement if you like:
https://editor.datatables.net/manual/php/joins#Closure---custom-function
Something like this could work (not tested). It uses the built-in Editor db-handler which is typically called $db. If you called it differently you would need to change that in the code below.