Table Joins: Does Editor have support for "Or" statements and "Sum Of"?
Table Joins: Does Editor have support for "Or" statements and "Sum Of"?
pansengtat
Posts: 66Questions: 26Answers: 1
in Editor
I am trying to extract data from a datatable with a SQL query like this:
select *
from myrequests
where (status = 1 OR assigned_group = 4)
So far in Editor, I have been able to only write this in the backend:
$data = Editor::inst($db, 'myrequests', 'request_id')
->where('myrequests.status', 1)
->where('myrequests.assigned_group', 4)
->field(
Field::inst('myrequests.remarks')->validator('Validate::notEmpty')
)
->leftJoin('myrequestdata', 'myrequests.request_id', '=', 'myrequestdata.request_id')
->process($_POST)
->data();
However, the above code is reading the "where" clause as "and".
Another question: "Sum of" statements
Is there a way to edit the core Editor/Datatables files, eg) Join.php to include "sum of" SQL functions?
This question has accepted answers - jump to:
This discussion has been closed.
Answers
Hi,
In Editor 1.4 you can use an anonymous function for the
where()
method to get access to the underlying query and its more complete where operations. For example:Regarding sums - currently it is not possible to use SQL functions in Editor fields. You would need to calculate the sum externally to the libraries I'm afraid.
Allan
I attempted to use the query method in your reply, but I myself get an invalid JSON error. Would appreciate if this can be fixed:
Missing quote mark - sorry. Should be:
Did the error in the Ajax return give an error message that agrees with that?
Allan
Apparently, inside the
function($q)
could not recognize constants or variables which are declared in external files. But if a magic number is used, it just fits in well. Weird.They can, but you need to use the
use()
statement:This is all part of PHP's awful handling of globals and variable scope... I quite like PHP, but it does have issues such as this - particularly if you are used to Javascript.
Allan