where data in object - join - edit

where data in object - join - edit

RafaelGarciaRafaelGarcia Posts: 20Questions: 1Answers: 0

as I can do a "-> where ()" of an object after a join,
  eg $ out = $ editor -> where ('table1.table_id', '1', '=') -> process ($ _ POST) -> data ();
  Echo json_encode ($ out);

table1 is the result of a -> join

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    I'm not sure what your question is? That looks like it should work okay.

    Allan

  • RafaelGarciaRafaelGarcia Posts: 20Questions: 1Answers: 0
    edited February 2015

    comprehensive information and copy the code to make it more real. generates an error message.

    ```php
    Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'tms_fallas.falla_nombre' in 'where clause'' in /var/www/tms/php/lib/Database/Driver/Mysql/Query.php:98

    <?php

    /*
    * Editor server script for DB table tms_slots
    * Automatically generated by http://editor.datatables.net/generator
    */

    // DataTables PHP library
    include( "lib/DataTables.php" );

    // Alias Editor classes so they are easy to use
    use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Join,
    DataTables\Editor\Validate;

    // Build our Editor instance and process the data coming from _POST
    $editor = Editor::inst( $db,'tms_novedades','novedad_id')

    ->fields(
    
        Field::inst( 'novedad_fechaInicio' ),               
        Field::inst( 'novedad_fechaCierre' ),                   
        Field::inst( 'novedad_estado' ),
        Field::inst( 'novedad_id' )
    
    
        )
    
        ->join( 
    
    
            Join::inst( 'tms_fallas', 'object' )
                ->join( 
                    array('novedad_id', 'novedad_id' ),
                    array('falla_id', 'falla_id' ),
                    'tms_novedades_fallas'
                    )
    
                    ->fields(
    
                    Field::inst( 'falla_id' ),                  
                    Field::inst( 'falla_nombre' ),
                    Field::inst( 'falla_icon' )             
                ) ,
    
            Join::inst( 'tms_slots', 'object' )
                ->join( 
                    array('novedad_id', 'novedad_id' ),
                    array('slot_id', 'slot_id' ),
    
                    'tms_novedades_slots'
                    )
    
                    ->fields(
    
                        Field::inst( 'slot_id' ),               
                    Field::inst( 'slot_numeroCetsa' ),
                    Field::inst( 'slot_numeroOnline' ),
                    Field::inst( 'slot_numeroSerie' ),
                    Field::inst( 'slot_numeroCetsa' )
                )   
        );
    

    $out = $editor ->where('tms_fallas.falla_nombre','carlos paz')->process($_POST) ->data();
    echo json_encode( $out );

    <?php > ``` ?>

    the idea is that each user only change the assigned fields according to their city, so wanted to use "where" to filter them according to the case.

    I'm doing wrong !!!
    thanks for help

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    The error message is saying that there is no column in the table called tms_fallas.falla_nombre.

    Allan

  • RafaelGarciaRafaelGarcia Posts: 20Questions: 1Answers: 0

    when he used works perfect

    $out = $editor ->where('novedad_estado','cerrada')->process($_POST) ->data();
    echo json_encode( $out );

    {"id":-1,"error":"","fieldErrors":[],"data":[],"aaData":[{"DT_RowId":"row_1","novedad_fechaInicio":"2015-02-05 09:24:34","novedad_fechaCierre":"0000-00-00 00:00:00","novedad_estado":"cerrada","novedad_id":"1","tms_fallas":{"falla_id":"1","falla_nombre":"bloqueo juego","falla_icon":"<i title=\"fuera de servicio\" class=\"splashy-error\"><\/i>"},"tms_slots":{"slot_id":"1","slot_numeroCetsa":"A-2500","slot_numeroOnline":"22500","slot_numeroSerie":"DX010214V"}}]}

    when used as follows, and error does not work.
    the tms_fallas table exists and falla_nombre culmna there.

    $out = $editor ->where('tms_fallas.falla_nombre','bloqueo juego')->process($_POST) ->data();
    echo json_encode( $out );

    I'm doing wrong !!! thanks for help

  • RafaelGarciaRafaelGarcia Posts: 20Questions: 1Answers: 0

    will be the version I am using?

    thanks for help

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Are you still getting the same error message when you use where('tms_fallas.falla_nombre','bloqueo juego')? The error message states that a column by that name doesn't exist. Perhaps there is a typo?

    Allan

  • RafaelGarciaRafaelGarcia Posts: 20Questions: 1Answers: 0

    allan,

    the problem is that the column is the result of a join table with a link !!!! and when 'tms_fallas.falla_nombre' use gives me the error but if use 'novedad_fechaInicio' works well.

    'tms_novedades' is the name of a table and 'novedad_fechaInicio' is the name of a column.

    'tms_fallas' is a table name and 'falla_nombre' is the name of a column.

    'tms_novedades_fallas' is the link table.

    thanks for help

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    I see the issue now - thanks for the explanation.

    So the problem is that you are applying the where condition to the editor top level table, but the join is a separate query as you have it set up at the moment.

    What I would suggest is that you use a leftJoin rather than the Join class since you are only using a one-to-one join (i.e. objects).

    Then you will be able to apply the where expression to the main Editor.

    The alternative is to apply the where to your Join instance which will reduce the result set of that join (NOT the overall data set) to just that option. Which might be what you want...

    Allan

  • RafaelGarciaRafaelGarcia Posts: 20Questions: 1Answers: 0

    Reproduce your suggestion and it worked
    thanks for help

This discussion has been closed.