User with records having age attributes, what does this query return?User.where(age: 20..30).pluck(:name)
where and pluck do in ActiveRecord.The where(age: 20..30) filters users with age between 20 and 30 inclusive. The pluck(:name) extracts only the name attribute values from those filtered records, returning an array of names.
where.Option A uses a raw SQL condition with a placeholder, which is the correct syntax. Option A is invalid syntax for range or comparison. Option A is invalid Ruby syntax. Option A uses an invalid range syntax in a hash.
users table has 10 records with active true and 5 with false, what does this return?User.where(active: true).limit(3).count
count works with limit in ActiveRecord.The count method respects limit and counts only the limited number of records. So it counts 3 active users, not all 10.
User.where(name: 'Alice').order(:nonexistent_column)
Why does it raise an error?
The error occurs because order tries to sort by a column that does not exist in the database table, causing a database error.
ActiveRecord builds query objects lazily. The actual database query runs only when the data is accessed, such as by iterating or calling methods like to_a.