Options->where( function )
Options->where( function )
Hello,
I am trying to implement the Options->where( function ) as described for exemple here.
Here is my code:
Field::inst( 'quote.quote_datetime' )
->options( Options::inst()
->where( function ($q) { $q->where( 'quote.quote_datetime', '( SELECT MAX(quote.quote_datetime) FROM quote left Join patrimoine_instruments ON quote.quote_isin = patrimoine_instruments.instrument_ISIN WHERE patrimoine_instruments.instrument_ISIN = quote.quote_ISIN LIMIT 1;)', '=', false); })),
which returns "DataTables warning: table id=patrimoines - An SQL error occurred: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM WHERE (quote
.quote_datetime
= ( SELECT MAX(quote.quote_datetime) FROM' at line 1"
When I replace quote.quote_ISIN
by a value that is in the datatable,like:
Field::inst( 'quote.quote_datetime' )
->options( Options::inst()
->where( function ($q) { $q->where( 'quote.quote_datetime', '( SELECT MAX(quote.quote_datetime) FROM quote left Join patrimoine_instruments ON quote.quote_isin = patrimoine_instruments.instrument_ISIN WHERE patrimoine_instruments.instrument_ISIN = 'FR0000050353' LIMIT 1;)', '=', false); })),
it returns DataTables warning: table id=patrimoines - Ajax error. For more information about this error, please see https://datatables.net/tn/7 code 500.
I know that the SELECT query below is correct because runing this query returns a correct value:
SELECT MAX(quote.quote_datetime) FROM quote left Join patrimoine_instruments ON quote.quote_isin = patrimoine_instruments.instrument_ISIN WHERE patrimoine_instruments.instrument_ISIN = 'FR0000050353' LIMIT 1;
so I guess the problem comes from the rest of the code.
Any idea on where it could come from?