Bubble edit not updating left joined table

Bubble edit not updating left joined table

Tech360Tech360 Posts: 6Questions: 5Answers: 0
edited July 2018 in Editor

I am using the php library of editor and
joining 2 tables using leftjoin()

    $editor = Editor::inst( 
    $db, 
    'humans' ,  //  Table name
    'pid'           //  Primary key
    )->fields(
        Field::inst( 'humans.name' ),
        Field::inst( 'students.email' ),
        Field::inst( 'humans.phone' ),

        //  To get options
        Field::inst( 'students.course' )
            ->options( Options::inst()
                ->table('courses')
                ->value('pid')
                ->label('name')
        ),
        Field::inst( 'courses.name' )

    )
    ->leftJoin( 'students', 'students.humanid', '=', 'humans.humanid' )
    ->leftJoin( 'courses', 'courses.pid', '=', 'students.course' )
    ->process( $_POST )
    ->json();

Everything is working fine if I use the normal edit.

But in case of bubble edit only the columns of the first table (in my case humans) is getting updated properly. If I try to update the courses it won't work

Here is the javascript and html

          editor = new $.fn.dataTable.Editor( {
              ajax: {
                url: "private/data.php",
                data: {
                  key : "123"
                },
                type: "POST"
              },
              table: "#example",
              fields: [ {
                    label: "Name:",
                    name: "humans.name"
                }, {
                    label: "Phone:",
                    name: "humans.phone"
                }, {
                    label: "Email:",
                    name: "students.email"
                }, {
                    label: "Course:",
                    name: "students.course",
                    type: "select"
                }
              ]
          } );
          
          $('#example').on( 'click', 'tbody td', function (e) {
              editor.bubble( this );
          } );

          $('#example').DataTable( {
              // serverSide: true,
              dom: "Bfrtip",
              ajax: {
                url: "private/data.php",
                data: {
                  key : "123"
                },
                type: "POST"
              },
              columns: [
                  { data: "humans.name" },
                  { data: "humans.phone" },
                  { data: "students.email" },
                  { data: "courses.name", editField: "students.course" }
              ],
              select: true,
              buttons: [
                  { extend: "create", editor: editor },
                  { extend: "edit",   editor: editor },
                  { extend: "remove", editor: editor }
              ]
          } );

<table id="example" class="display" style="width:100%">
        <thead>
            <tr>
              <th>Name</th>
              <th>Phone</th>
              <th>Email</th>
              <th>Course</th>
              <th>Status</th>
            </tr>
        </thead>
    </table>

Can anybody help me with this one?

This question has an accepted answers - jump to answer

Answers

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

    Hi,

    To update fields in the leftJoined table's you need to submit the primary key of the joined table's record along with the new value for the field being changed. The hidden field type can be used for that.

    You'll probably also need to use formOptions.bubble setting the submit option to allIfChanged as well to make sure that all of the information is being submitted on edit.

    Allan

  • Tech360Tech360 Posts: 6Questions: 5Answers: 0

    Thanks @allan it worked! :smiley:

This discussion has been closed.