What is ORM as it applies to Rails and what does it mean?
ORM is Object Relational Mapper. It means you don't have to manually call the database yourself; the ORM handles it for you.
Ruby on Rails uses one called ActiveRecord, and it's a really good one.
ORM allows you to do things such as:
User.find(50).contacts
Instead of manually writing a SELECT statement with JOINs, WHEREs, etc.
ORM stands for Object-Relational-Mapping. It basically means that Active Record takes data which is stored in a database table using rows and columns, which needs to be modified or retrieved by writing SQL statements (if you're using a SQL database), and it lets you interact with that data as though it was a normal Ruby object.
Example: Suppose you want to fetch an array of all the users then instead of writing any code for database connection and then writing some SQL query like SELECT * FROM users
and converting the result into an array, I can just type User.all
and Active Record gives me that array filled with User objects that I can play with as I'd like.
It doesn't really matter which type of database you're using. Active Record smooths out all the differences between those databases for you so you don't have to think about it. You focus on writing code for your application, and Active Record will think about the nitty gritty details of connecting you to your database. It also means that if you switch from one database to another, you don't actually need to change any major application code, just some configuration files.
ORM is Object Relational Mapper. It means you don't have to manually call the database yourself; the ORM handles it for you. Ruby on Rails uses one called ActiveRecord, and it's a really good one.
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.
> Perform database operations in an object-oriented fashion.
click hear
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