0
0
Ruby on Railsframework~5 mins

Database table naming conventions in Ruby on Rails - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the general rule for naming database tables in Rails?
Tables should be named in plural form using lowercase letters and underscores to separate words, for example, users or order_items.
Click to reveal answer
beginner
Why does Rails use plural table names by default?
Rails uses plural table names to match the convention that a table holds many records of a model, which is usually singular. For example, the User model corresponds to the users table.
Click to reveal answer
beginner
How should multiple words be combined in a Rails table name?
Use lowercase letters with underscores between words, called snake_case. For example, order_items instead of OrderItems or orderitems.
Click to reveal answer
intermediate
What happens if you name a table in singular form in Rails?
Rails may not automatically map the table to the model correctly, causing errors or requiring manual configuration to specify the table name.
Click to reveal answer
beginner
Give an example of a correct table name for a model named InvoiceItem.
The correct table name would be invoice_items, using plural form and snake_case.
Click to reveal answer
In Rails, what is the correct table name for a model named ProductCategory?
Aproductcategorys
BProductCategories
Cproductcategory
Dproduct_categories
Why should Rails table names be plural?
ABecause tables store multiple records
BBecause models are plural
CBecause Rails does not support singular names
DBecause SQL requires plural table names
Which of these is NOT a recommended Rails table naming convention?
AUsing snake_case
BUsing plural names
CUsing camelCase
DUsing lowercase letters
What problem might occur if a table is named in singular form?
ARails may not map the model to the table correctly
BRails will automatically fix it
CThe database will reject the table
DThere is no problem
How should you separate words in a Rails table name?
AWith spaces
BWith underscores
CWith hyphens
DNo separation, just camelCase
Explain the Rails convention for naming database tables and why it is important.
Think about how Rails connects models and tables automatically.
You got /5 concepts.
    Describe what could happen if you do not follow Rails table naming conventions.
    Consider how Rails expects table names to relate to model names.
    You got /4 concepts.