Moodle
  1. Moodle
  2. MDL-29668

xmldb does not generate correct code for foreign-unique key

    Details

    • Testing Instructions:
      Hide

      1. Edit an xmldb file.
      2. Go in and edit a table (you will need one with an id-ish field that doesn't already have an index on it).
      3. Add a key.
      4. Choose foreign-unique type. Enter the name of the field in the current table, and details of another table such as id field in course_sections. Save the form.
      5. Click 'View php code', choose 'Add key' and select the key

      Check that the generated code includes the constant XMLDB_FOREIGN_UNIQUE and includes the details of the other table (course_sections, id)

      Show
      1. Edit an xmldb file. 2. Go in and edit a table (you will need one with an id-ish field that doesn't already have an index on it). 3. Add a key. 4. Choose foreign-unique type. Enter the name of the field in the current table, and details of another table such as id field in course_sections. Save the form. 5. Click 'View php code', choose 'Add key' and select the key Check that the generated code includes the constant XMLDB_FOREIGN_UNIQUE and includes the details of the other table (course_sections, id)
    • Workaround:
      Hide

      To get correct code, copy the code used for generating a normal foreign key and edit XMLDB_KEY_FOREIGN to XMLDB_KEY_FOREIGN_UNIQUE.

      Show
      To get correct code, copy the code used for generating a normal foreign key and edit XMLDB_KEY_FOREIGN to XMLDB_KEY_FOREIGN_UNIQUE.
    • Affected Branches:
      MOODLE_20_STABLE, MOODLE_21_STABLE, MOODLE_22_STABLE
    • Fixed Branches:
      MOODLE_20_STABLE, MOODLE_21_STABLE
    • Pull from Repository:
    • Pull Master Branch:
    • Rank:
      19174

      Description

      If you add a foreign-unique key (normally used for 1:1 relationships), this is correctly stored in the install.xml, but if you get xmldb to generate the php code, it is incorrect.

        Activity

        Hide
        Eloy Lafuente (stronk7) added a comment -

        Sending to integration, thanks for the report.

        Show
        Eloy Lafuente (stronk7) added a comment - Sending to integration, thanks for the report.
        Hide
        Sam Hemelryk added a comment -

        Thanks Eloy - this has been integrated now

        Show
        Sam Hemelryk added a comment - Thanks Eloy - this has been integrated now
        Hide
        Sam Marshall added a comment -

        thanks eloy

        Show
        Sam Marshall added a comment - thanks eloy
        Hide
        Aparup Banerjee added a comment -

        works for me.

        results :
        if ($oldversion < XXXXXXXXXX)

        { // Define key testkeydeleteme (foreign-unique) to be added to block_search_documents $table = new xmldb_table('block_search_documents'); $key = new xmldb_key('testkeydeleteme', XMLDB_KEY_FOREIGN_UNIQUE, array('courseid'), 'course_sections', array('id')); // Launch add key testkeydeleteme $dbman->add_key($table, $key); // search savepoint reached upgrade_block_savepoint(true, XXXXXXXXXX, 'search'); }
        Show
        Aparup Banerjee added a comment - works for me. results : if ($oldversion < XXXXXXXXXX) { // Define key testkeydeleteme (foreign-unique) to be added to block_search_documents $table = new xmldb_table('block_search_documents'); $key = new xmldb_key('testkeydeleteme', XMLDB_KEY_FOREIGN_UNIQUE, array('courseid'), 'course_sections', array('id')); // Launch add key testkeydeleteme $dbman->add_key($table, $key); // search savepoint reached upgrade_block_savepoint(true, XXXXXXXXXX, 'search'); }
        Hide
        Eloy Lafuente (stronk7) added a comment -

        Many thanks for the hard work developing and testing this. It has been spread to cvs and git upstream repositories.

        Closing, ciao

        Show
        Eloy Lafuente (stronk7) added a comment - Many thanks for the hard work developing and testing this. It has been spread to cvs and git upstream repositories. Closing, ciao

          People

          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: