0
0
Ruby on Railsframework~20 mins

Database table naming conventions in Ruby on Rails - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Rails Table Naming Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Pluralization of table names in Rails
In Rails, what is the conventional way to name database tables for models?
AUse plural form of the model name, e.g., 'users' for User model
BUse singular form of the model name, e.g., 'user' for User model
CUse uppercase model name as table name, e.g., 'User' for User model
DUse camelCase model name as table name, e.g., 'userProfile' for UserProfile model
Attempts:
2 left
💡 Hint
Think about how Rails automatically maps models to tables.
🧠 Conceptual
intermediate
2:00remaining
Naming join tables for many-to-many relationships
How should you name a join table for a many-to-many relationship between models 'Author' and 'Book' in Rails?
Aauthor_book
Bauthors_books
Cbooks_authors
DauthorBooks
Attempts:
2 left
💡 Hint
Rails expects join tables to be named alphabetically and pluralized.
query_result
advanced
2:00remaining
Effect of incorrect table naming on ActiveRecord queries
Given a Rails model named 'ProductCategory' but the database table is named 'productcategory', what will happen when you run ProductCategory.all?
AIt will return all records from the 'productcategory' table without error
BIt will return an empty array because no matching table is found
CIt will raise an ActiveRecord::StatementInvalid error because the table name does not match the expected 'product_categories'
DIt will automatically find the 'productcategory' table ignoring naming conventions
Attempts:
2 left
💡 Hint
Rails expects table names to be plural and underscored by default.
schema
advanced
2:00remaining
Custom table name declaration in Rails model
How can you specify a custom table name 'inventory_items' for a Rails model named 'Item'?
A
class Item < ApplicationRecord
  self.table_name = 'inventory_items'
end
B
class Item < ApplicationRecord
  table_name = 'inventory_items'
end
C
class Item < ApplicationRecord
  set_table_name 'inventory_items'
end
D
class Item < ApplicationRecord
  @table_name = 'inventory_items'
end
Attempts:
2 left
💡 Hint
Look for the correct syntax to override the table name in Rails models.
optimization
expert
3:00remaining
Optimizing queries with table naming and indexing
You have a large Rails app with a table named 'user_sessions' storing millions of records. Which naming and indexing strategy helps optimize queries filtering by 'user_id'?
ARename the table to 'user_sessions_data' and add a composite index on 'user_id' and 'session_token'
BRename the table to 'usersessions' and add a unique index on 'user_id'
CKeep the table named 'user_sessions' and do not add any indexes
DKeep the table named 'user_sessions' and add an index on the 'user_id' column
Attempts:
2 left
💡 Hint
Think about Rails conventions and indexing for query speed.