Where Clause inside Left Join

Where Clause inside Left Join

alf007alf007 Posts: 37Questions: 15Answers: 0

Hi!

I would like to know if the Editor can handle where clauses inside left joins?

Thanks.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,812Questions: 1Answers: 10,516 Site admin
    Answer ✓

    You should simply be able to use the joined fields like any other field:

    Editor::inst( $db, 'users' )
        ->field(
            Field::inst( 'users.first_name' ),
            Field::inst( 'users.last_name' ),
            Field::inst( 'users.phone' ),
            Field::inst( 'users.site' )
                ->options( 'sites', 'id', 'name' )
                ->validator( 'Validate::dbValues' ),
            Field::inst( 'sites.name' )
        )
        ->leftJoin( 'sites', 'sites.id', '=', 'users.site' )
        ->where( 'sites.name', 'Edinburgh' )
        ->process($_POST)
        ->json();
    

    Allan

  • alf007alf007 Posts: 37Questions: 15Answers: 0

    Thanks Allan.

  • alf007alf007 Posts: 37Questions: 15Answers: 0
    edited April 2016

    :)

  • mikeswebmikesweb Posts: 5Questions: 1Answers: 0

    how do you specify "in" i.e.,
    ->where( 'sites.name','Edinburgh','Glasgow')
    or something like that?

  • allanallan Posts: 63,812Questions: 1Answers: 10,516 Site admin

    How to use operators such as IN is documented here.

    Allan

  • mikeswebmikesweb Posts: 5Questions: 1Answers: 0

    I am asking how in the controller.cs file, not in php tho

  • allanallan Posts: 63,812Questions: 1Answers: 10,516 Site admin

    Sorry. You didn't mention that and you used PHP syntax. Here is the equivalent documentation for the .NET libraries.

    Allan

This discussion has been closed.