• Resolved jtomte

    (@jtomte)


    Hi,
    First of all thanks for a very useful plugin!

    Is it possible to do update/save to multiple tables?

    I have a shortcode view that uses an INNER JOIN and I get an error when i try to save changes.

    Joined columns are not detected in field list.

    Uncaught TypeError: Cannot use ‘in’ operator to search for ‘length’ in <div id=”error”><p class=”wpdberror”>WordPress database error: [Unknown column 'navn' in 'field list']<br />

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author bobbysmith007

    (@bobbysmith007)

    Howdy! By default the plugin only supports saving to a single table. If all the columns you need to update are on a single table of your multitable query, you can use noedit_columns to prevent it from send certain columns to the database.

    EX: SELECT A.id, A.a, A.b, A.c, B.d FROM A JOIN B ON A.id = B.aid
    noedit_columns=”d”
    Will prevent the B columns from being sent as part of the update.

    If you need to update data from multiple tables you will have to write custom form save hooks. There should be both reasonable documentation and examples in the examples dir for setting up custom save hooks. Custom save hooks will allow you to send 2 updates (one to each table).

    Thread Starter jtomte

    (@jtomte)

    Thanks for swift reply!

    [SOLVED]

    noedit_columns worked like a charm!
    Fortunately I dont need to update those two joined columns. It is only for readability. Meaningful text instead of foreign key indexes.
    Here’s what I did:
    I have two joined columns, each from separate tables, that needs to be protected from editing.

    $noedits = array('join_table_1', 'join_table_2');

    add_db_table_editor(
    array(
    'title' => 'h1_title',
    'id' => '1',
    'editcap' => 'manage_options',
    'id_column' => 'id',
    'table' => 'table_name',
    'cap' => 'manage_options',
    'noedit_columns' => $noedits,
    'sql' => $join_sql)
    );

    Again, thanks for a great plugin! Saves me a lot of work ??

    • This reply was modified 8 years ago by jtomte.
    • This reply was modified 8 years ago by jtomte.
    • This reply was modified 8 years ago by jtomte.
    Plugin Author bobbysmith007

    (@bobbysmith007)

    Wonderful, glad you could get it working!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Error when saving due to INNER JOIN’ is closed to new replies.