Skip to content

Ruby class:Day 6- Rails – Active record

23/12/2010

This day i know about Active record.

Rails uses ORM ( Object Relational Mapping)

usually we connect the database using the queries with in the quote through the languages.

queries are slightly different to various databases like Oracle, MySql, etc., in this case doesn’t change database one to another

if wants means change all queries as per the databases.

but Rails provide active_record concept . It is an Domain Specific language

we connect the database via rails not use the DB queries. so we can easily change various databases.

Mr. Thayagarajan explained the comparisons of usual way and active_record(rails)

active_record example:


require 'rubygems'
require 'active_record'
ActiveRecord::Base.establish_connection(:adapter => "mysql",:host => "localhost",:username => "root",:password => "password",:database => "rubyclass")
class Student < ActiveRecord::Base
belongs_to :standard
end
class Standard <  ActiveRecord::Base
has_many :students
end
all_students = Student.find(:all)
all_students.each do |child|
puts child.name + child.standard.name
end

Rails installation in tamil here.

http://coachfactory.blogspot.com/2010/07/blog-post.html

Advertisements

From → Ruby

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: