I'm working on a custom stock management plugin for a client's Craft Commerce site, and I need to have relations from my custom element type (used to keep a detailed log of stock changes) to the products and variants, and the user or order that modified the stock.
I've looked at the Events plugin, as well as Craft & Commerce's source code, but I'm still struggling to write my
modifyElementsQuery in such a way that allows me to access the content of these other elements without directly joining from the content table (which seems like a terrible way of going about it).
What's the right way of relating two element types together? Is there any example code I can look at (either in Craft core, or an open-source plugin)?