error when trying to use sql function combined with where statement
error when trying to use sql function combined with where statement
javismiles
Posts: 205Questions: 38Answers: 3
Im trying to avoid creating a view and instead do this
$editor->fields(
Field::inst( 'SUM(imp.amount)', 'work.spend' )
// ->set( false )
->where( function ($q) {
$q->where( 'imp.type', '1', '=' );
}
);
$editor->leftJoin( 'imp', 'imp.workid', '=', 'work.id' );
but it just wont work, instead of sending all the rows it sends just one and it also gives error when trying to use the where statement
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
this actually almost works except that it returns just 1 row instead of the many rows it was returning before
$editor->fields(
Field::inst( 'SUM(workimp.amount)', 'worksol.spend' ))
// ->set( false )
->where( function ($q) {
$q->where( 'workimp.type', '1', '=' );
});
that happens because in this specific case the left join necessary
$editor->leftJoin( 'workimp', 'workimp.solid', '=', 'worksol.solutionid' );
has many cases where there is nothing to match in that table,
how can I make sure that a left join doesnt constrain the rest of my joins,
that if a specific row doesnt have a match with that other table, the row is still returned?
Yes, because there is no
where()
method on theField
object. It is only on theEditor
object.This is very similar to your other thread on this topic. Let's continue the discussion there.
Allan
agreed, closing this one