+1-757-461-3022 x124

ORM — Object Relational Mapping

An ORM is an Object Relational Mapping that defines the relationship between object oriented type definitions and relational tables or views in a database. This implementation is currently designed  to apply specifically to a PostgreSQL database, but theoretically could be applied to any database for which an ORM API is defined to process these definitions. The xTuple ORM can be found on GitHub.

In the xTuple PostgreSQL implementation the installation of ORM files triggers views to be created whose structures and rules conform to the definition of the ORM. The ORMs use camel and class case conventions when referencing object attributes and snake case conventions when referencing database attributes. Because ORMs generates views, these views can in turn be referenced by other ORMs to manage a class hierachy. To determine the name of a view created by an ORM simply convert the name space qualified type of the object to a snake case schema and view name like so:

Object Name      Datbase Name
--------------   ----------------
XM.Contact       xm.contact
XM.ToDo          xm.to_do
XM.ToDoComment   xm.to_do_comment

ORMs are specifically designed to be extensible so that a database table can be virtually expanded without changing the original table definition, while presenting the new data through the ORM API as though it were all one unit. This effectively ensures that "core" database definitions and custom or 3rd party data extensions are effectively encapuslated from one another. In addition ORMs can be activated and deactivated in the xt.orm table so extensions can be "turned off" at any time.

The initial ORM is referred to as the "base" ORM. Additional ORMs can be defined against the original base using the same name space and type but giving them a different context name and setting the isExtension flag to true. Typically the table on an ORM extension should reside in a different database schema where you would create a table with colums that contain data you want to "add" to a table in the original schema. The new table should contain a column relation to associate with the original (which may also be the primary key for it as well.) When you create an ORM extension the new table will be left joined on the original. Any inserts, updates or delete actions will propagate results to both the original and the new table automatically.

Extensions can be created as both completely independent ORM definitions or added to an extension array on a base or extension ORM.

4 users have voted.