Editor gives error if your database table has no id column

Editor gives error if your database table has no id column

zapatazapata Posts: 13Questions: 5Answers: 1

Editor gives error if your database table has no "id" column. Some tables has column like "cityid" instead of "id" (cityid is unique)
if it is like that; Editor gives issue.

Answers

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    How about some real details? For debugging?..

  • zapatazapata Posts: 13Questions: 5Answers: 1

    DataTables warning: table id=b_hareket_table - SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'field list

    Unknown column 'id' ??? I cant see any "id" in my codes

    Client Side:

    <table class="responsive_table" id="b_hareket_table" style="width:100%">
        <thead>
            <tr>
    
                <th>First</th>
                <th>Second</th>
    
            </tr>
        </thead>
    </table>
    <script>
        table=$('#b_hareket_table').DataTable( {
        ajax: {
                url: "vendor/api/getFromEditorResults.php",
                type: 'POST'
            },
            columns: [
    
                { data: function ( row, type, set ) {
                    console.log(row);
                        return "hello";
                }},
                                        
                { data: function ( row, type, set ) {
                    console.log(row);
                        return "USA";
                }}
            ]
        });
    </script>
    

    Server Side
    getFromEditorResults.php:

    include( "__editor/php/DataTables.php" );
    
    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Join,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate;
    
    
    Editor::inst( $db, 'radacct' )
        ->field( 
            Field::inst( 'radacct.radacctid as thisIsMyId' ),
            Field::inst( 'radacct.username as username' )
        )
    ->where('radacct.username','morsltd','=')
        ->process($_POST)->json();
    
  • allanallan Posts: 63,353Questions: 1Answers: 10,444 Site admin

    Hi,

    You can use the optional third parameter in the Editor constructor to tell Editor what the primary key column name is - e.g.:

    Editor::inst( $db, 'radacct', 'cityid' )
    

    This is noted in the basic initialisation documentation but it isn't as obvious as it should be. I'll improve that!

    Thanks,
    Allan

This discussion has been closed.