What has been in the works lately? It'll blow your mind.

Generic placeholder image

This stuff is pretty amazing

Active Record

ActiveRecord is an example of a way to provide Object Relational Mapping (ORM). We can define an Object in a way that Ruby Understands and then communicate with a Database management system in SQL by way of the Ruby object interface.

ActiveRecord makes it possible to map one row from a relational database to an object in Ruby. This is an important part of what makes Ruby on Rails work. Database interactions are handled by this database to object mapping within the Ruby on Rails application. Active Record can enable a developer to create objects from a database from common Ruby syntax such as p = Post.last and then call other methods that create attributes of the object such as p.title in p.title = " A new title" and then communicate with a database to save the object with p.save

CRUD

For objects created from the database the CRUD functionality exists by default from Active Record. These functions are the most basic database operations.

Create appears as a method call in ruby syntax and can be invoked by simply by Post.new

Read is the basic function of retrieving data from the database and can be invoked by a method that will return the data such as Post.first or Post.last

Update is a function that will read, change and save after you modify the object in ruby you simply invoke the save feature or p.save.

Delete this enables us to elete an ActiveRecord object calling the ActiveRecord destroy method will destroy a database row using a DELETE query.

Associations

The associations between database tables are easily implemented in an ActiveRecord Model common associations are listed below:

belongs_torelationship
has-many
has_one
has_and_belongs_to_many

When these are declared at the top of the ruby class file it builds Associations between tables of the database.

Validations

ActiveRecord can validate data integrity in Models

Validations are extremely important before data is saved to a database. With validations in the web app we can make sure that the data is clean and correct.

Two of the most common validations are uniqueness and presence. Other validations are formats of a string and type of data validation.