About
This use case demonstrates how to use table joins to pull data from a secondary table. By joining the course table with the course categories table, you can display the readable name of a category instead of just its ID number.
To access these settings, navigate to Site administration > Plugins > Local plugins > Dash Addons > Manage data sources and select Create custom data source.
1. General settings
Establish the identity of the data source and select the primary table.
Data source name: Courses with categories
ID number: courses-categories
Select main table (mnt): course
Click the Generate fields button.
2. Join tables
This step connects the course to its specific category record in the database.
Enable joins: Checked
Joint table #1
Select join table: course_categories
Table alias: cc
Enter condition query to join: mnt.category = cc.id
3. Fields setup
Define which details to display, using fields from both your main table and your joined table.
Placeholder fields: Select
course:id(mnt.id).Field #1
Field: course:fullname
Transform the format: Link
Additional format value: /course/view.php?id={mnt.id}
Field #2
Field: course:shortname
Transform the format: None
Field #3
Field: course_categories:name
Transform the format: None
4. Condition setup
Apply a filter to ensure the Moodle site home is not included in your list.
Enable conditions: Checked
Condition #1
Field: course:id
Operator: !=
Value: 1
How to use this data source
Once saved, add a Dash block to any page and select Courses with Categories from the "Build your own" section. You can then open the block preferences and enable the fields you wish to display within the Fields tab.