Views: 17671
Last Modified: 27.10.2022
ORM (Object-relational mapping) is a programming technique that connects databases with the concepts of object-oriented programming languages creating a "virtual object database" (Wikipedia).
Introduction
In the old core, its own GetList, Update, Add, and Delete are programmed for each entity.
Deficiencies of such method:
- Different set of parameters;
- Different syntax of the filter fields;
- Events may be existent or non-existent;
- Sometimes different code for different databases (
Add
).
New Core D7:
To make database selecting and saving operations uniform with the same parameters and filters. If possible, entity tables must be serviced with a minimum of a new code. Standard events of adding/changing/deleting must be available automatically.
The following notions were introduced to implement these purposes:
- Entities (Bitrix\Main\Entity\Base).
- Entity fields (Bitrix\Main\Entity\Field and its successors).
- Data manager (Bitrix\Main\Entity\DataManager).
An entity describes a table in the database, and also contains entity fields. The DataManager performs selection and entity change operations. In practice, the work is mostly done at the level of the DataManager.
Attention! Before starting development, ensure that the module you selected has classes methods from core D7. It can be checked by available description in the documentation
D7.
Note: This chapter provides abstract examples for purposes of clarification. Using the provided examples via copy\paste may not render the desired result for your specific project. Examples must be adapted for your specific code and database structure.