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

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

    XMLWordPrintable

Details

    • New Feature
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • 2.6.1
    • 2.7
    • 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 .

    Description

      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.

      Attachments

        Issue Links

          Activity

            People

              timhunt Tim Hunt
              timhunt Tim Hunt
              Sam Marshall Sam Marshall
              Dan Poltawski Dan Poltawski
              Ankit Agarwal Ankit Agarwal
              Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                12/May/14