Skip to content

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

Closed
harshil8595 wants to merge 2 commits into
grabs:mainfrom
harshil8595:main
Closed

Add support for derived relations in XMLDB and remove obsolete relations file#31
harshil8595 wants to merge 2 commits into
grabs:mainfrom
harshil8595:main

Conversation

@harshil8595

Copy link
Copy Markdown
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.

@harshil8595

Copy link
Copy Markdown
Contributor Author

Hi @grabs

I understand you may be busy, but I would really appreciate it if you could take a look when you have some time.

Please let me know if any changes or additional information are needed from my side. I’d be happy to update the PR accordingly.

Thank you for your time and for maintaining this project.

grabs pushed a commit that referenced this pull request Mar 14, 2026
grabs added a commit that referenced this pull request Mar 14, 2026
@grabs

grabs commented Mar 14, 2026

Copy link
Copy Markdown
Owner

Hello, thank you very much for this useful addition!
I’ve made a few small adjustments and simplified the code a bit.
In my opinion, a function should ideally not return different data types.
The comments were also not entirely consistent.
But as I said, these were only minor things.
Thanks again for your work!

@grabs grabs closed this Mar 14, 2026
@harshil8595

Copy link
Copy Markdown
Contributor Author

Hi @grabs ,

Thanks for your time and efforts.

@harshil8595

Copy link
Copy Markdown
Contributor Author

Hi @grabs,

Can you add me as contributor in this plugin on moodle.org?

I've messaged you my moodle userid to your moodle account.

It will be grealy appreciated

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.

2 participants