Setting a WHERE in options.

Setting a WHERE in options.

MickBMickB Posts: 103Questions: 25Answers: 2
edited January 2016 in General

Hi,

I have a select which is getting populated from a joined table but it doesn't seem to be using my WHERE.
The application name should only be pulled back, if applications.deleted_at is null.

      Editor::inst( $db, 'roles' )->where('roles.deleted_at',null)
        ->fields(
            Field::inst( 'roles.id' ),
            Field::inst( 'roles.deleted_at' ),
            Field::inst( 'roles.created_at' ),
            Field::inst( 'roles.updated_at' ),
            Field::inst( 'roles.name' )->validator( 'Validate::notEmpty')->validator(         'Validate::unique'),

           //This is where the problem is
            Field::inst( 'roles.application_id' )
                ->options('applications','id','name')
                ->validator( 'Validate::dbValues' ),


            Field::inst( 'applications.name' )
        )

        ->leftjoin('applications','applications.id','=','roles.application_id' )
        ->where('applications.deleted_at',null)
        ->process( $_POST )
        ->json();
}

Does that make sense?

Mick

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,453Questions: 1Answers: 10,055 Site admin

    That should work - I've just tried a little test locally and it does appear to work as expected. What version of the libraries are you using?

    Allan

  • MickBMickB Posts: 103Questions: 25Answers: 2

    Strange, when I do an edit, the dropdown is showing deleted applications (deleted_at is populated with a date)

    This is the ajax response from the page load:

    {"data":[{"DT_RowId":"row_1","roles":{"id":"1","deleted_at":null,"created_at":"2016-01-04 16:29:08","updated_at":"2016-01-04 16:29:16","name":"adminRole","application_id":"1"},"applications":
    {"name":"webUserManager"}},{"DT_RowId":"row_4","roles":{"id":"4","deleted_at":null,"created_at":"2016-01-06 12:58:54","updated_at":"0000-00-00 00:00:00","name":"AdminSelection","application_id":"5"},"applications":{"name":"selection"}}],

    //Some of these have deleted_at which contains a date.
    "options":{"roles.application_id":[{"label":"aaa","value":"4"},{"label":"dsad","value":"3"},{"label":"fdsfds","value":"2"},{"label":"selection","value":"5"},{"label":"webUserManager","value":"1"}]},"files":[]}

    Looks like version 1.5.3

  • allanallan Posts: 61,453Questions: 1Answers: 10,055 Site admin
    Answer ✓

    Ah! This is the drop down options that you want to limit?

    You need to use the Field->options() method for that. See the options documentation.

    Allan

  • MickBMickB Posts: 103Questions: 25Answers: 2

    Bingo!

    Many thanks Allan.

This discussion has been closed.