Is there any difference between Actice Record and ORM? some of the documentations says both are same. is that true?
1.3 Active Record as an ORM Framework Active Record gives us several mechanisms, the most important being the ability to: Represent models and their data. Represent associations between these models. Represent inheritance hierarchies through related models. Validate models before they get persisted to the database.
ActiveRecord is an ORM. It's a layer of Ruby code that runs between your database and your logic code.
Rails Active Records provide an interface and binding between the tables in a relational database and the Ruby program code that manipulates database records. Ruby method names are automatically generated from the field names of database tables.
In Rails, ORM is implemented by Active Record which is one of the most important components of the Rails library. An ORM provides a mapping layer between how a database handles its data and how an object-oriented application handles its data.
Object Relational Mapping (ORM) is the technique of accessing a relational database using an object-oriented programming language. Object Relational Mapping is a way to manage database data by "mapping" database tables to classes and instances of classes to rows in those tables.
Active Record is just one of such ORMs, others include:
Read more here https://github.com/learn-co-students/active-record-mechanics-crud-v-000#orm-vs-active-record
Object Relational Mapping (ORM):
simplify the use of databases in applications.
Use objects to hold database records
Attributes of an object correspond to columns from the row
ActiveRecord Basics
Model: A Rails class corresponding to a database table ActiveRecord:
Example Table
<table>
<tbody>
<tr>
<th> id </th>
<th>name</th>
<th>birth</th>
<th>gpa</th>
<th>grade</th>
</tr>
</tbody>
<tbody>
<tr>
<td> 1 </td>
<td> Anderson </td>
<td> 1987-10-22 </td>
<td> 3.9 </td>
<td> 2009 </td>
</tr>
<tr>
<td> 2 </td>
<td> Jones </td>
<td> 1990-04-16</td>
<td> 2.4 </td>
<td> 2012 </td>
</tr>
</tbody>
</table>
Create a class for this table (app/models/student.rb):
class Student < ActiveRecord::Base
end
Or, just use the script/generate program:
ruby script/generate model student
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With