Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-44251

DB helper method to re-order rows with a unique index

XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Fixed
    • Icon: Blocker Blocker
    • 2.7
    • 2.6.1
    • Libraries
    • MOODLE_26_STABLE
    • MOODLE_27_STABLE
    • Hide

      Run the unit tests. The new tests in lib/tests/datalib_update_with_unique_index_test.php provide good coverage. This is not yet used anywhere, but will be used in MDL-43749.

      Show
      Run the unit tests. The new tests in lib/tests/datalib_update_with_unique_index_test.php provide good coverage. This is not yet used anywhere, but will be used in MDL-43749 .

      Suppose we have a DB table like

              Unique index
           including these cols
                v         v
      ---------------------------
      id  | otherid | sortorder | ...
      ---------------------------
      123 |   2345  |      1    | ...
       45 |   2345  |      2    | ...
       67 |   2345  |      3    | ...
      890 |   2345  |      4    | ...
      ... other rows relating to other otherids ...
      

      And suppose you want to re-order the sortorders like

      1 => 4
      2 => 1
      3 => 3
      4 => 2

      You need to do this in the right order, so as to avoid violiating the unique index at any stage.

      I am about to implement this for the second time, so I plan to do it as a utility method.

            timhunt Tim Hunt
            timhunt Tim Hunt
            Sam Marshall Sam Marshall
            Dan Poltawski Dan Poltawski
            Ankit Agarwal Ankit Agarwal
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.