ActiveRecord ORM and SQL querying
ActiveRecord is an ORM
Active record is a ORM(Object Relational Mapping) library. This means that even though you’re interacting with a database in your Rails app by writing
User.find_by you’re not really writing SQL but writing with a DSL(Domain Specific Language) called ActiveRecord to compile SQL code to interact with the SQL database. So in console I type
which uses the ActiveRecord Library to execute this hidden SQL code into the database:
This outputs an ActiveRecord hash containing a user found by the query in the database.
Here we use the development database from SteamFriend.me to fetch a user with an id of 1.
You can find out more on the official Rails ActiveRecord ORM here