I have quite a lot of experience with Magento but I realized that I don't understand which way of loading a model is the correct one and why. I've read everything that I could, about the topic but people explaining stuff like this never actually go deep enough to explain, why use this specific method instead of another. Let's assume there is no repository for the model I want to load.
Up untill now I was always using model in constructor and then simply load it.
public function __construct(
\Vendor\Module\Model\Something $somethingModel
) {
$this->somethingModel = $somethingModel;
}
public function getTestById($id) {
return $this->somethingModel->load($id);
}
And it always worked as intended, I'm also pretty sure it's or at least was used commonly in core.
But then I saw one of my colleagues using
modelFactory->create()->load($id)
As far as I understand factories are being used to create a new entity, for example, if I wanted to create a new product then I can create the factory, populate it with data and then save it. But then again, I started researching the topic and I saw example from Fabian Schmengler (When Should We Use a Repository and Factory in Magento 2?) who was loading the model this way and also discouraged others from simply loading the models, he didn't explain why though besides saying that it's 'not part of the service contract'. As far as I understand repositories are part of service contracts so I don't see any connection here when it comes to loading models that are not available through a repository.
To add some more confusion I've also found a way of loading the model by getting the resourceModel from created modelFactory, it was presented by Vinai Kopp (How to implement service contract for a custom module in Magento 2?) and now I'm completely lost as I've always read that I shouldn't use resource models directly.
So yeah, could somebody tell me which is the correct way and why I should use it instead of all of the other methods?