[{"id":"railsbeginner-001","courseId":"rails-beginner","domain":"data-modeling","topic":"Table names from model class names","prompt":"You create a model class named LineItem. Which table name does Active Record use for it by default?","hint":"Compare the capitalization, word breaks, and number of the class name with the table name.","explain":"Active Record links each model class to a table by a naming rule. The rule covers capitalization, word separators, and grammatical number.","source":"https://guides.rubyonrails.org/active_record_basics.html#naming-conventions","interaction":{"type":"single"},"options":[{"id":"a","text":"LineItems","whyNot":"Table names are snake_case, not UpperCamelCase; UpperCamelCase is for the class name."},{"id":"b","text":"line_item","whyNot":"Table names are plural, so the singular form is wrong for a table."},{"id":"c","text":"line_items","why":"Active Record uses the plural of the class name in snake_case, with words separated by underscores."},{"id":"d","text":"tbl_line_items","whyNot":"Rails adds no tbl_ prefix; the table is just the plural, snake_case form of the class name."}],"answer":"c","explanation":"Model class names are singular UpperCamelCase; the matching table name is plural snake_case, so LineItem maps to line_items.","concept":"Model class names are singular UpperCamelCase; the matching table name is plural snake_case, so LineItem maps to line_items.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["A model's table name is the plural, snake_case form of its class name."]},{"id":"railsbeginner-002","courseId":"rails-beginner","domain":"data-modeling","topic":"Default primary key column","prompt":"In a new Rails app on PostgreSQL, a table created by a migration gets an id primary key of type integer by default.","hint":"Think about how big the default id is and whether that differs between databases.","explain":"Every Active Record table gets a primary key unless you change it. The column type for that key depends on which database engine stores the data.","source":"https://guides.rubyonrails.org/active_record_basics.html#schema-conventions","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"PostgreSQL gets bigint for the default id; integer is the default only on SQLite."},{"id":"b","text":"False","why":"The default id is bigint on PostgreSQL, MySQL and MariaDB, and integer only on SQLite."}],"answer":"b","explanation":"Active Record's default id is bigint on PostgreSQL, MySQL and MariaDB, and integer on SQLite.","concept":"Active Record's default id is bigint on PostgreSQL, MySQL and MariaDB, and integer on SQLite.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["The default id is bigint on PostgreSQL, MySQL and MariaDB, and integer on SQLite."]},{"id":"railsbeginner-003","courseId":"rails-beginner","domain":"data-modeling","topic":"Creating tables with migrations","prompt":"The migration below creates a products table. Which TWO statements about the resulting table are true?","hint":"Consider which columns appear without being written, and what a rollback undoes.","explain":"A migration is a Ruby description of a schema change that Active Record applies in both directions. Some parts of the result come from defaults rather than from lines you write.","source":"https://guides.rubyonrails.org/active_record_migrations.html#creating-a-table","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"You must hand-edit db/schema.rb to match the new table.","whyNot":"Active Record updates db/schema.rb itself to match the database; you don't write it by hand."},{"id":"b","text":"The table has an id primary key, though the block never declares one.","why":"Active Record adds id as the default primary key, so the block doesn't have to list it."},{"id":"c","text":"Rolling the migration back empties the table but keeps it in place.","whyNot":"A rollback reverses the change, and this migration's change was creating the table, so the table goes."},{"id":"d","text":"The table is created when the app boots, not when the migration runs.","whyNot":"Before the migration runs there is no table; running the migration is what creates it."},{"id":"e","text":"Rolling the migration back removes the products table.","why":"The migration is reversible, and reversing it removes the table it created."},{"id":"f","text":"Only created_at is added, because t.timestamps creates a single column.","whyNot":"t.timestamps adds two columns, created_at and updated_at, not one."}],"answer":"be","explanation":"create_table adds an implicit id primary key, and the migration is reversible, so rolling it back drops the table.","concept":"create_table adds an implicit id primary key, and the migration is reversible, so rolling it back drops the table.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","code":"create_table :products do |t|\n  t.string :name\n  t.text :description\n  t.timestamps\nend","takeaways":["Migrations add id automatically and roll back by dropping the table they created."]},{"id":"railsbeginner-004","courseId":"rails-beginner","domain":"data-modeling","topic":"Timestamp columns","prompt":"A migration adds t.timestamps to a people table. Later the app saves Person records. Which statement about created_at and updated_at is true?","hint":"Think about whether these two columns need code to fill them in, and who does it.","explain":"The timestamps macro creates two columns in one line. Active Record has special behavior for columns with these names, and that behavior decides who fills them in.","source":"https://guides.rubyonrails.org/active_record_migrations.html#creating-a-table","interaction":{"type":"single"},"options":[{"id":"a","text":"You must assign both columns yourself on every save, or they stay NULL.","whyNot":"Active Record manages these columns itself, so you don't fill them in by hand."},{"id":"b","text":"Active Record manages them automatically when the columns exist.","why":"The timestamps macro creates these columns, and Active Record manages them automatically when they exist."},{"id":"c","text":"Active Record ignores them unless you list them in a validation.","whyNot":"No validation is needed; Active Record manages these columns automatically when they exist."},{"id":"d","text":"They are added only when the model class calls t.timestamps in Ruby code.","whyNot":"t.timestamps is a migration macro; it creates the two columns in the table."}],"answer":"b","explanation":"t.timestamps adds created_at and updated_at, which Active Record manages automatically when the columns exist.","concept":"t.timestamps adds created_at and updated_at, which Active Record manages automatically when the columns exist.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["t.timestamps adds created_at and updated_at; Active Record manages them automatically."]},{"id":"railsbeginner-005","courseId":"rails-beginner","domain":"data-modeling","topic":"Rolling back the latest migration","prompt":"A migration created the products table. A developer rolls that migration back. What happens to the products table?","hint":"Think about what Active Record does with the change a migration defines when run in reverse.","explain":"A migration describes a change moving forward in time. Active Record can also run that description backward, and the reverse run is what a rollback does.","source":"https://guides.rubyonrails.org/active_record_migrations.html#rolling-back","interaction":{"type":"single"},"options":[{"id":"a","text":"The table is kept, but all of its rows are deleted.","whyNot":"A rollback reverses the change the migration made; here that change was creating the table."},{"id":"b","text":"The table is removed.","why":"Active Record knows how to reverse create_table, so rolling back drops the table."},{"id":"c","text":"The table is renamed to products_old.","whyNot":"Rollback does not rename anything; it reverses the migration's create step."},{"id":"d","text":"Nothing changes in the database; only db/schema.rb is updated.","whyNot":"The rollback changes the database, and db/schema.rb is then updated to match it."}],"answer":"b","explanation":"Active Record knows how to reverse create_table, so rolling back the migration removes the table.","concept":"Active Record knows how to reverse create_table, so rolling back the migration removes the table.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["A rollback reverses a migration; reversing create_table drops the table."]}]