ORM Patterns: Active Record vs Data Mapper
In one of the least-relevant-to-WordPress articles I published there, I recently covered the difference between an active record ORM system vs one using the data matter pattern. ORMs are essentially systems by which PHP (or any language) objects are stored-to and retrieved-from the database.
Why this isn’t particularly relevant to WordPress, is that WordPress has no ORM. It has a global database object,
$wpdb and a host of functions that read and write values to the database. But that’s about it as far as ORMs go. (There’s more about
$wpdb in this article, if you’re looking. 🤓)
So why share it? One, self-promotion. (Also, I just did an economic analysis of my coffee habit. 😝) But, two, I think one of the long-standing deficiencies of the WordPress ecosystems especially with respect to development practices is a sort of insularity with respect to learning and talking about concepts above-and-beyond WordPress. Understanding what ORMs are and how they work makes one a better developer. Full stop.
I don’t think WordPress needs an ORM. I don’t think that you should write your own ORM for your plugin (although that’s a reasonable idea at a big-enough plugin-scope). But I do think you should know about and be conversant in this (and other) common application pattern if you’re going to be the best possible WordPress developer.