Can i use a static array instead of join ?

Can i use a static array instead of join ?

ziv@kpmbro.comziv@kpmbro.com Posts: 73Questions: 28Answers: 4

Hi

I want to save on queries and instead of "join" the same table over and over , i want to use a static array.

for example : (lets say i got all the "sites" table in a php array )

https://editor.datatables.net/examples/inline-editing/join.html

how can i tell the client side to show the editField from the array?

Thanks.

This question has an accepted answers - jump to answer

Answers

  • ziv@kpmbro.comziv@kpmbro.com Posts: 73Questions: 28Answers: 4
    edited July 2016

    found it

    Field::inst( 'users.site' )
        ->options( function () {
            return array(
                array( 'value' => 'EDI', 'label' => 'Edinburgh' ),
                array( 'value' => 'LON', 'label' => 'London' ),
                array( 'value' => 'NEW', 'label' => 'New York' ),
                array( 'value' => 'SAN', 'label' => 'San Francisco' )
            );
        } );
    

    I am getting the right values in the dropdown when pressing to edit.
    But after I press update i get the this error:

    "Table for database value check is not defined for field offers_main_table.is_offer_pushed_to_another_platform"

    this is my code for the static join:

    <?php
    Field::inst("offers_main_table.is_offer_pushed_to_another_platform")->options( function () {
                                return array(
                                    array( 'value' => 0, 'label' => "FALSE" ),
                                    array( 'value' => 1, 'label' => "TRUE" )
                                );
                            } )->validator( 'Validate::dbValues');
    ?>
    

    what did i miss?

    Thanks

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • allanallan Posts: 61,642Questions: 1Answers: 10,092 Site admin
    Answer ✓

    Hi,

    The issue is that you are using the dbValues validator to validate that the value submitted is in the database list of options, but as you note above there is no database list of options! Hence the error :-).

    You should use the values built in validation method to check if the submitted value is in a set of values (i.e. an array you defined).

    Regards,
    Allan

  • ziv@kpmbro.comziv@kpmbro.com Posts: 73Questions: 28Answers: 4
    edited July 2016

    Thanks thats was the problem. :)

    Allan does the custom validator method will effect the the values i want to show in the editField?

    right now i am not getting any.

    How should i point with the editField, because its not really a field in a table its an element in array. (can i point at the key of the element some how)?

    Thanks

This discussion has been closed.