Why use Active Record?
Active Record is a Ruby gem, which connects our database to Ruby. This allows our data to persist through multiple sessions. Additionally Active Record uses Object-Relational-Mapping to create relationships between our data, allowing us to call on those relationships through Ruby. Lastly using our database to process queries, allows for a faster, and more efficient processing time.
- column_names: Returns a list of column names.
2. update_all(): Updates all selected records, returns the number of records update.
3. pick(): Returns the first result value(s) from the relation.
4. pluck(): Returns an array of attribute values matching the plucked column name(s).
5. map() Returns an array of attribute values matching the plucked column name(s).
6. select(): Returns a relation object(s) corresponding to the requested value(s).
7. exists()Returns a boolean indicating if any record with the given conditions exist.
8. eql? Compares two objects and returns boolean, indicating if the items match.
- .where: return the object(s) that matches the conditions.
- LENGTH() in quotes is the SQL command, finds the length of the argument.
- or Allows for a second condition.
- .join: (Inner Join) uses the foreign key to create a “virtual table” between the two classes. Pulls in the details of the class it is being called on (ex. Country, not Traveler class). The “virtual table” will also EXCLUDE any details from relationships that don’t exist. (ex. If a Country does not have a traveler, or a traveler does not have a country, they will not be on the table.)