https://github.com/thandon263/activerecord_sql
https://github.com/thandon263/activerecord_sql
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/thandon263/activerecord_sql
- Owner: thandon263
- Created: 2016-06-19T17:44:41.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-06-19T17:44:50.000Z (almost 9 years ago)
- Last Synced: 2025-01-06T01:10:36.217Z (5 months ago)
- Size: 1000 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SQL and ActiveRecord
# 1a) Find the genre with the name "Hip Hop/Rap".
Genre.where(name:'Hip Hop/Rap')
# 1b) Count how many tracks belong to the "Hip Hop/Rap" genre
Genre.where(name:'Hip Hop/Rap').count
# 2) Find the total amount of time required to listen to all the tracks in the database.
Track.sum("milliseconds")
# 3a) Find the highest price of any track that has the media type "MPEG audio file".
Track.where(media_type_id:MediaType.where(name:'MPEG audio file').first.id
).maximum('unit_price')# 3b) Find the name of the most expensive track that has the media type "MPEG audio file".
Track.where(media_type_id:MediaType.where(name:'MPEG audio file').first.id, unit_price:Track.where(media_type_id:MediaType.where(name:'MPEG audio file').first.id
).maximum('unit_price')
).first.name# 4) Find the 2 oldest artists.
Artist.order(created_at: :asc).first(2)
* Columns: attributes, name, data type
* Row: Record, represents a set of data for each column
* Primary key: `id` unique
* can be an integer (starts at 1 and 10000000)
* UUID 349tu-hbe0984-5hww9e8y5h* Foreign key:
Allows you to associate to another table
`objectname_id`----------------------------------------------------------
Read on ACID
Sanitization - looking at basically the valid input
find_by - It gives you back an ActiveRecord
where - returns an array of objects ("NOT specific")-- You can chain methods on Records of a database
---------------------Migrations----------------------------
DDL -- Changes the structure the datatbase