CSC/ECE 517 Fall 2013/ch1 1w43 av: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 21: Line 21:
The diagram below depicts a simple mapping of an object to a database table….
The diagram below depicts a simple mapping of an object to a database table….


[[Image:orm.jpg]]
[[Image:ORM.jpg]]


ORMs are crucial to almost any application that needs to access a database, as they provide the connection from the model of the program to the database itself. By enabling database rows to be used as objects, the program can more easily access and use the information in a way that is internally consistent and easy to understand. The ORM gives the programmer to manipulate data with the programming language, instead of having to manipulate each attribute as its data type as obtained by the database management system.
ORMs are crucial to almost any application that needs to access a database, as they provide the connection from the model of the program to the database itself. By enabling database rows to be used as objects, the program can more easily access and use the information in a way that is internally consistent and easy to understand. The ORM gives the programmer to manipulate data with the programming language, instead of having to manipulate each attribute as its data type as obtained by the database management system.

Revision as of 23:11, 5 October 2013

Introduction

Object-relational mapping (ORM) provides developers with a set of tools that ease management of the relationships between objects and relational databases, thus allowing applications to be easily extended to add data persistence. For Ruby, several object-relational mapping options are available. This wiki concentrates more on the comparison of ORMs and provides a high level overview of the top Ruby ORMs: ActiveRecord ,Sequel and DataMapper. It also includes a minor discussion on alternative frameworks that can be used either in place of or along with ORMs. These include the persistence framework iBATIS (more specifically the Ruby version RBatis).

Overview

Object-relational Mapping (ORM) frameworks unburden the designer of the complex translation between database and object space.

ORM features constitutes the following:

  • It binds an object to its data in the database.
    • Class instance variables to database columns
    • Class instances to table rows
  • It depicts associations, properties and behaviors related to tables and their fields.
    • Example, :has_many, :belongs_to associations in ActiveRecord
    • Inheritance cases are mapped to tables
  • It manages the process of converting data between its database and object forms.
  • It performs validation of data before it is persisted to table storage.
  • It generates the SQL for a relational database to perform Create Read Update Delete operations in response to the changes made to the data objects within the application.

The diagram below depicts a simple mapping of an object to a database table….

ORMs are crucial to almost any application that needs to access a database, as they provide the connection from the model of the program to the database itself. By enabling database rows to be used as objects, the program can more easily access and use the information in a way that is internally consistent and easy to understand. The ORM gives the programmer to manipulate data with the programming language, instead of having to manipulate each attribute as its data type as obtained by the database management system.

When applied to Ruby, implementations of ORM often leverage the language’s metaprogramming strengths to create intuitive application-specific methods and otherwise extend classes to support database functionality. With the addition of Rails, the ORM becomes much more important, as it is necessary to have an ORM to connect the models of the MVC (model-view-controller) stack used by Ruby on Rails with the application's database. Since the models are Ruby objects, the ORM allows modifications to the database to be done through changes to these models, independent of the type of database used.

With the release of Rails 3.0, the platform became ORM independent. With this change, it is much easier to use the ORM most preferred by the programmer, rather than being corralled into using one particular one. To allow this, the ORM needed to be extracted from the model and the database, to be a pure mediator between the two. Then any ORM can be used as long as it can successfully understand the model and the database used.