$editor ->where does not work

$editor ->where does not work

leighJaneleighJane Posts: 21Questions: 3Answers: 0

This is the way you say to do a WHERE in the editor and it breaks the ajax call. Works fine without it.
```
// Build our Editor instance and process the data coming from _POST
$editor = Editor::inst( $db, 'InvoiceLine' )
$editor ->fields(
Field::inst( 'customer_full_name' )
->validator( Validate::notEmpty( ValidateOptions::inst()
->message( 'A name is required' )
) ),
Field::inst( 'customer_id' ),
Field::inst( 'OrderNumber' ),
Field::inst( 'OrderStatus' ),
Field::inst( 'GeminiOrderNo' ),
Field::inst( 'shippedFrom' ),
Field::inst( 'shippedDate' )
->validator( Validate::dateFormat( 'm-d-Y' ) )
->getFormatter( Format::dateSqlToFormat( 'm-d-Y' ) )
->setFormatter( Format::dateFormatToSql('m-d-Y' ) ),
Field::inst( 'ShippedVia' ),
Field::inst( 'TrackingNumber')
)

$editor ->where( 'OrderStatus', 'shipped',  '!=')
    ->where( 'GeminiOrderNo' ,'null' ,'!=');

$editor
->process( $_POST )
->json();

<?php > ``` ?>

This question has an accepted answers - jump to answer

Answers

  • leighJaneleighJane Posts: 21Questions: 3Answers: 0

    I got it working by not using $editor before ->where( 'OrderStatus', 'shipped', '!=') but I was unable to get the 2nd WHERE working but thats not an issue

  • colincolin Posts: 15,237Questions: 1Answers: 2,599
    Answer ✓

    Glad, working, I think for the second one you need:

    ->where( function ( $q ) {
        $q->where( function ( $r ) {
            $r->where( 'OrderStatus', 'shipped',  '!=')
            $r->or_where( 'GeminiOrderNo' ,'null' ,'!=');
      } );
    } );
    

    See here for more info,

    Colin

  • leighJaneleighJane Posts: 21Questions: 3Answers: 0

    Thanks Colin :)

This discussion has been closed.