Rails study questions Flashcards
(96 cards)
What part of MVC is Active Record?
M- the model
What is the model layer of the system responsible for?
Representing business data and logic.
What does Active Record facilitate?
The creation and use of business objects whose data requires persistent storage to a database.
What is the Active Record pattern a description of?
An Object Relational Mapping system.
What are two features of objects in Active Record?
Objects carry both persistent dat and behavior which operates on that data.
How will ensuring data access logic as part of the object educate users?
It will educate users on how to write to and read from the database.
What is Object Relational Mapping?
ORM is a technique that connects the rich objects of an application to tables in a relational database management system.
What are two advantages of using ORM?
You don’t have to write SQL statements directly and you need less overall database access code.
What are five mechanisms Active Record gives us?
- 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.
What is a configuration advantage of creating Active Record models?
Explicit configuration is needed only in those cases where you can’t follow the standard convention.
What is optimistic locking?
It allows multiple users to access the same records for edits, and assumes a minimum of conflicts with the data. It does this by checking whether another process has made changes to a record since it was opened.
What does a lock_version column name do?
It adds optimistic locking to a model.
What does a “type” column name do?
Specifies that the model uses Single Table Inheritance.
What is Single Table inheritance?
Inheritance via storing the name of the class in a column that is named “type” by default.
What does an “(association_name)_type” column name do?
Stores the type for polymorphic associations.
What does an “(table_name)_count” column name do?
Used to cache the number of belonging objects on associations.
What does creating an ActiveRecord::Base model allow you to map?
The columns of each row in a database table with the attributes of the instances of your model.
What are three methods you can use to override naming conventions?
self.table_name =
set_fixture_class table_name: ClassName
self.primary_key =
What is the difference between create and new?
The new method will return a new object while create will return the object and save it to the database.
What does CRUD stand for?
Create, Read, Update, Delete
What happens if a block is provided to new or create?
if a block is provided, both create and new will yield the new object to that block for initialization:
What is the method to delete an Active Record object?
destroy
What is a useful method for updating several records in bulk?
update_all
What does validation allow?
Active Record allows you to validate the state of a model before it gets written into the database.