Answer the question
In order to leave comments, you need to log in
How to properly implement relationships between models?
Good afternoon.
How would you implement relationships between models? for example:
There is a reseller model, it has various relationships, one to many, one to one, etc.
In this model, more and more new connections are constantly appearing, for example:
Connection with the sales list, connection with orders, baskets, storefronts, pages, etc. and this list is constantly growing.
This approach is very convenient for me, because there is a central model that depends on the authorized user and through it you can get any connected data. (because it’s convenient reseller->getSales(), reseller->getCarts(), etc.)
But I don’t like that such a model grows quickly, and it turns out some kind of GOD class that knows everything and everyone, in violation all SOLID principles.
UPD:
the example in the question is not real, but purely for the question invented.
reseller acts as a factory that creates the desired smaller entity depending on the ID of the reseller. This class itself (reseller) can be divided into smaller factories, like: creating a sales subsystem, settings subsystem, etc., and through them you can already get smaller entities of each of the subsystems.
Or is it all somehow cunning to wrap DependencyInjection \ServiceLocator
Or something else?
So the question is, how would you do it?
Answer the question
In order to leave comments, you need to log in
As an option:
1. Creation of models: order, basket, showcase, page, etc. One model may use relationships with other tables. As a rule, one model is one business entity of the application. Contains only CRUD functions.
2. To reduce the links between models, you can create an abstract class level that will implement business logic, interaction between models. For example shop->createOrder() gets the contents of the cart and creates an order.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question