insert_record() function changes...

insert_record() function changes...

by Eloy Lafuente (stronk7) -
Number of replies: 1
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Peer reviewers Picture of Plugin developers Picture of Testers
Hi moodlers,

currently the insert_record() function, part of lib/datalib.php is defined as:
function insert_record($table, $dataobject, $returnid=true, $primarykey='id')
and I would want to discuss a bit about the 4th parameter in such definition, i.e. the $primarykey one.

It's primary goal is to allow Moodle DB tables to have primary key fields whose name was different from the standard "id" auto-numbered field (point 1).

After some discussions in this looong bug, it seems that, ASAP, we should delete such 4th parameter completely, to 100% enforce all Moodle tables to have such standard "id" field. Moodle's style, you know!

Currently under Moodle official code there aren't any line using that parameter so, form that perspective, we could delete that parameter now.

But, perhaps, this would make some contrib modules to stop working suddenly and we don't want this to happen, isn't it? wink

So, this discussion has, at least, two objectives:

1.- To inform all developers about the need to check their code, ensuring that all their DB tables have the "id" PK, auto-numbered field and that they aren't using the 4th field in their insert_record() calls.

2.- To discuss how we could give to developers some time to adapt their code without breaking it now. About this, I think we could start sending some "deprecated" info to the browser with "debug" enabled, plus some "error_log" messages to general log files. Then, after some weeks/months/releases, we could delete such 4th parameter safely forever.

How does this sound for you?

Ciao smile
Average of ratings: Useful (2)