S
S
Sergey2019-06-19 11:06:27
Doctrine ORM
Sergey, 2019-06-19 11:06:27

Doctrine inheritance or something else?

It is necessary to make accounts in the system for conducting mini accounting. The problem is that these accounts (at the moment) come in 4 different types: external, system, user, corporate.
The external and system ones are no different and contain only the main properties of the account: id, currency, value.
User and corporate, in addition to the main properties, must be somehow connected with the corresponding entities: user and company.
What is the best way to implement this through the Doctrine or in general from a DBA point of view?
1. I tried to put all accounts in one table using STI ( Doctrine: Single Table Inheritance). But this method has a minus - accounts will always eager-load in the entities that are associated with them. That is, if I get a user, then the account will already be contained in it, which means Doctrine performs an additional request.
2. I also tried the option to use many-to-many connections with unique keys, in which case one-to-one actually turns out, but through an intermediate (pivot) table. In this case, everything seems to be working, but the user's $account field is now not just an Account, but an ArrayCollection. Although this collection will actually always store one Account object.
All this about accounts in one table accounts. You can, of course, make MappedSuperClass and make N tables with accounts, but then you get a lot of tables with about the same structure. IMHO it does not look very good, but maybe this is how it should be done? Interested in your opinions

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question