โ Ruby on Rails learning pathRuby on Rails ยท Module 3 of 10
Models and Active Record
Active Record maps database tables to Ruby classes.
๐ Key ideas
- A Product model maps to a products table by convention.
- Product.create(name: "Pen", price: 10) inserts a row.
- Product.find(1), Product.where(price: ..100), Product.order(:name) query rows.
- product.update(price: 12) and product.destroy change or delete.
- Each row becomes an object with attribute methods.
๐ก Real-life example: Like a translator between Ruby and SQL: you speak Ruby, and it writes the SQL for you.
Active RecordRails ORM linking classes and tables
ORMObject-relational mapping
whereFilter rows by conditions
findFetch a row by id