The simple answer is that when the Moodle project started, it the database that was available was MySQL
3.x. (Of course, some people was hesitate to call that a relational database.) Since then, some things have been improved, but the key outstanding issue is that Moodle does not use foreign key constraints.
(However, if you look at the database definitions, which are stored in a database neutral way in in files called install.xml
in each plugin, you will see that foreign key relations are defined there.)
My view is that we should make the effort to deal with this some time. That is, create all the foreign keys, and then fix all the error messages we get as a result. However, I am still in a minority there. (Search for other threads about foreign keys to see the past discussions.)
There are also some weird relations in some of the older tables, like the links between couse, course_modules, course_sections, etc. Again this is historical, and probably too painful to change now.
I can't acutally help you with the code flow for enrolment plugins. However, you need to note that by default, the serach on Moodle Docs
does not include the developer documentation. See the note at the top of Development:Developer_documentation
. Also, some of the links there may help, for example Development:Enrolment_plugins
. If all else fails, you will have to read the code.