As we all know, magento 2 suggests using repositories as an additional layer between resource models/collections and the rest of application. It's all pretty straightforward and simple when you use it for single tables. Majority of multi-table query results are obtained in magento 2 sourcecode using collections instead of repositories. I suppose that it's an inconrect way, as for instance extension attributes (which are recommended to be plugged only to repositories) won't load with those collections.

So my question is: what's the official recommended way to handle multi-table source of data in repositories?

Some ways that come to my mind are:

  • always join all possibly required tables (obviously terrible performance)
  • additional repositories/methods for every set of required joins (lots of redundant code and additional plugining when you use mechanisms such us extension attributes)
  • ignore repositories and use raw collections (additional plugins for mechanism such us extension attributes)
  • 'lazy' join additional tables to collections inside repositories when certain predefined fields are in filters (unobvious usage, dirty code I would say).

But none of solutions above looks reasonable to me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.