where clause in mjoin?

where clause in mjoin?

mfmf Posts: 41Questions: 11Answers: 0

Hello, does anyone know if it is possible to use a where clause in mjoin? like this:

   ->join(
        Mjoin::inst( 'dealers' )
            ->link( 'dealercontacts.dealercontacts_id', 'dealers_dealercontacts.dealercontacts_id' )
            ->link( 'dealers.dealernr', 'dealers_dealercontacts.dealernr' )
            ->order( 'dealernr asc' )
            ->fields(
                Field::inst( 'dealernr' )
                    ->validator( 'Validate::required' )
                    ->options( Options::inst()
                        ->table( 'dealers' )
                        ->value( 'dealernr' )
                        ->label( array('dealernr', 'naam', 'bezoek_plaats') )
                        ->where( function ( $r ) {
                            $r->or_where( 'contract', 'M' );
                            $r->or_where( 'contract', 'S' );
                            $r->or_where( 'contract', 'SAT' );
                            $r->or_where( 'contract', 'REP' );
                        } )
                    ),
                Field::inst( 'naam' )
            )
    )

I can't find it in the manual so I guess it is not possible. As alternative I could create a view of the dealer table where I leave out anything but M, S, SAT and REP. I don't need to write anything to that table.

Thanks!!

This question has accepted answers - jump to:

Answers

  • dataBdataB Posts: 23Questions: 5Answers: 1
    Answer ✓

    Great question. I used a view to handle a situation like this. However, from the documentation it seems like it should work.(https://editor.datatables.net/docs/1.7.2/php/class-DataTables.Database.Query.html)

    Did you try it with just one of the options?

    ex:

    ->where( function ($q) {
         $q->where( 'contract', 'M' );
    }
    
    

    If that doesn't work then you should probably use a view.

  • allanallan Posts: 49,623Questions: 1Answers: 7,317 Site admin
    Answer ✓

    Yes the Mjoin class has a where method that you can use to apply conditions to what is joined.

    Allan

  • mfmf Posts: 41Questions: 11Answers: 0

    thanks, it works!!

  • naspersgaspnaspersgasp Posts: 53Questions: 14Answers: 1

    Hi,

    Good day.

    Do you have an example of this in NodeJS? Thanks.

    Regards.

  • allanallan Posts: 49,623Questions: 1Answers: 7,317 Site admin
    editor.where( function () {
      this.where( 'contract', '=', 'M' )
    } )
    

    wold be the equivalent in Node. More on using conditions in Node available here.

    Allan

  • naspersgaspnaspersgasp Posts: 53Questions: 14Answers: 1

    Thanks Allan. Works.

Sign In or Register to comment.