editor php working for data loading, action remove is returning empty json

editor php working for data loading, action remove is returning empty json

MaikelMaikel Posts: 75Questions: 18Answers: 1

Hey,

i'm using editor php to load a serverside datatables, this all works perfectly, but when i add the remove(delete) something starts to be wierd.

the button works, i get the confirmation pop-up and when i hit confirm the post is happening, but the returned data from the post is empty, see below:

{"data":[],"debug":[]}

so it seems as there is no query ran and that seems to confirm what i see, the action remove/delet is not happening.

any idea where to start looking?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @Maikel ,

    That's the expected response, see an example here. Why do you think it isn't deleting - does the row stay in the table in the browser?

    Cheers,

    Colin

  • MaikelMaikel Posts: 75Questions: 18Answers: 1

    Hey ,

    yes after the delete the row is still there ...
    i expected a delete query in the debug output ...

    Maikel

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    You need to add ->debug(true) to your Editor PHP configuration chain (note, add it before the ->process(...) call).

    Allan

  • MaikelMaikel Posts: 75Questions: 18Answers: 1

    that is there, so it is enabled.

    for the load of the data it works and i see the queries

  • MaikelMaikel Posts: 75Questions: 18Answers: 1

    i started to debug this a bit

    and the problems seems to be in the '_remove_table' function of the Editor class
    the following if is not returning true,

    $this->_part( $field->dbField(), 'table' ) === $table
    

    i think this has something todo with the way we are using the db fields.

    we want to query a db from another database then the default one
    so we use:

    Editor::inst($db, '<dbname>.<tablename>', 'PK');
    

    as the fields we use

    Field::inst(`<dbname>.<tablename>.<fieldname>')
    

    $this->_part is correctly returning <tablename>
    but $table has the <dbname>.<tablename>

    so it looks like we either need to add the _part stuff here or the _tables var of the editor object is wrong

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Agreed. Do you need to specify the full database path like that for each field? Are you doing cross database joins? Or can you just drop the <dbname> part?

    Regarding the debug not being included, can you remind me what database engine you are using? It could be that on throwing an error the debug isn't being added.

    Allan

  • MaikelMaikel Posts: 75Questions: 18Answers: 1

    i use mysql as dbengine

    And yes i need the db path in there as i'm doing cross db joins in this specific case.

    The debug is empty because there was no sql command ran, in the _remove_table we exit before we can run the sql command

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Could you show me your PHP configuration for the Editor please and I'll try to reproduce the error here. That should actually work with PHP and MySQL, so I must have done something "funny" with it...

    Thanks,
    Allan

  • MaikelMaikel Posts: 75Questions: 18Answers: 1

    Below is the php code, it can be that i do something stupid :)

    note $cols is a list of all the column names for the table.
    in the getPDO we connect to db1

    $sql_details = array(
        "type" => "Mysql",
        "pdo"  => getPDO(True)
    );
            # Build the coll array
            $f  = array();
            foreach ( $cols AS $v ) { $f[] = Field::inst('db2.tbl1.'.'.$v); }
            $f[] = Field::inst('regressRun.link');
            $f[] = Field::inst('testbed.ipAddr');
            $f[] = Field::inst('testbed.name');
            # Build the editor
            $ed = Editor::Inst($db, 'db.tbl1', '_rdb_id');
            $ed->fields($f);
            # Join with the run table
            $ed->leftJoin( 'run', 'run.id', '=', 'db2.tbl._rdb_run_id' );
            $ed->leftJoin( 'regressRun', 'regressRun.id', '=', 'run.regressRun_id' );
            $ed->leftJoin( 'testbed', 'regressRun.testbed_id', '=', 'testbed.id' );
            if ( trim($_GET['branch']) != '' ) {
                $ed->where('_rdb_branch', trim($_GET['branch']));
            }
    
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Ah I think I see what it might be. You use the db names in the joins but not the fields. Can you add them there as well please? What you have is valid in SQL (assuming the names are unique), but Editor's parser isn't that smart...!

    Allan

  • MaikelMaikel Posts: 75Questions: 18Answers: 1

    so you mean adding the dbnames everywhere?

  • MaikelMaikel Posts: 75Questions: 18Answers: 1

    if i add the db to all fields and references to fields i have the same problem

    $table in Editor _remove_table is still the db.table name

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Okay thank you. I'll take a look into this on Monday and see if I can figure out what is going wrong.

    Allan

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    It ended up being Tuesday, but I have just committed the fix. You will need to have the db names everywhere as I suggested before, but this change will address the issue with not deleting the data.

    The db names everywhere isn't strictly required in Editor's code, but I've got it enforced since Editor doesn't attempt to do any object name conflict resolution like SQL does. This just forces you to be explicit with your intent.

    Regards,
    Allan

  • MaikelMaikel Posts: 75Questions: 18Answers: 1

    Hey Allan, this fixes my issue, thanks a lot

This discussion has been closed.