Blog Resume site ⇢

  • ORM 1: Entities

    Creating development environment for Lucee with Oracle Virtualbox, Linux and MySQL

    ORM stands for Object-Relation Mapping, and is a mechanism to tie together two different data representation methods: relational database tables ('relations' in terms of Relational model) and objects in object-oriented languages like Java or PHP.

    Let's introduce a 'relation': a table `users` in database `test`. See Prerequisites page for details.

    To manipulate data in this table we'll require write SQL statements - SELECTs, INSERTs, UPDATEs, DELETEs. This manipulation is often referred as CRUD operations (create-read-update-delete) and represents core of data manipulations in business software. Writing almost same code again and again can be quite mundate. What if something could generate this code for us? That's where ORM kicks in.

    Let's create CFC (Coldfusion Component, a close relative to Class in other OOP languages), which will represent one record ('tuple' in terms of Relational model). As seen, persistent attribute is set to true, meaning this CFC will be used in ORM, database table name is provided and columns of table are 'mapped' to fields of the resulting object.

    Now let's ask ORM system to retrieve table data for us:

    var users = EntityLoad("User");

    Resulting variable users will be an array of objects of type User. Let's render it with cfdump:

    More to read: Wikipedia,