Skip to content

Comments

Add support for derived relations in XMLDB and remove obsolete relations file#31

Open
harshil8595 wants to merge 1 commit intograbs:mainfrom
harshil8595:main
Open

Add support for derived relations in XMLDB and remove obsolete relations file#31
harshil8595 wants to merge 1 commit intograbs:mainfrom
harshil8595:main

Conversation

@harshil8595
Copy link
Contributor

Hi @grabs

I can't reopen existing PR

Add foreign key links support for component tables following componentname_object pattern

After the addition of foreign links support, I tested the feature with Moodle plugins tables and noticed an edge case related to tables belonging to components.

Currently, object table relations are automatically populated when column names match the pattern {object}id and a corresponding {object} table exists. For example, columns named courseid correctly link to the course table.

However, Moodle plugin tables follow a different naming convention:

componentname_object

For example:

  • Table: tool_customlang
  • Related table: tool_customlang_components
  • Field: componentid
  • Expected relation: tool_customlang.componentidtool_customlang_components.id

This relation is defined in Moodle’s install.xml:

<KEY NAME="fk_component" TYPE="foreign" FIELDS="componentid"
     REFTABLE="tool_customlang_components" REFIELDS="id"/>

But currently, Adminer does not automatically generate links for such component-based tables.


Steps to reproduce

  1. Visit
    {yourmoodle}/admin/tool/customlang/index.php

  2. Select a language

  3. Click
    Open language pack for editing

  4. Open table in adminer
    tool_customlang

  5. Observe field
    componentid

Expected result:
componentid should display links to records in tool_customlang_components

Actual result:
No relation link is shown


Proposed improvement

This PR extends the foreign link detection logic to support Moodle plugin table naming conventions:

componentname_object

This ensures relations such as:

tool_customlang.componentid → tool_customlang_components.id

are correctly detected and linked.


Benefits

This significantly improves debugging and developer productivity by allowing Moodle developers to:

  • Navigate table relations faster
  • Inspect related records directly
  • Debug database issues more efficiently

This is especially useful because Moodle defines logical foreign keys in XML but does not enforce them at the database level.


I am happy to make further improvements or adjustments based on your feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant