error when trying to use sql function combined with where statement

error when trying to use sql function combined with where statement

javismilesjavismiles Posts: 205Questions: 38Answers: 3
edited August 2018 in Editor

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

Answers

  • javismilesjavismiles Posts: 205Questions: 38Answers: 3

    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?

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin
    Answer ✓

    and it also gives error when trying to use the where statement

    Yes, because there is no where() method on the Field object. It is only on the Editor object.

    This is very similar to your other thread on this topic. Let's continue the discussion there.

    Allan

  • javismilesjavismiles Posts: 205Questions: 38Answers: 3

    agreed, closing this one

This discussion has been closed.