author avatar


Mon Mar 18 2024

Use pluck to fetch only the necessary columns if you don't need the entire object This reduces memory usage and database load

For example

 adults = User::User.where("age > ?", "18").pluck(:name)

The above code will return an array of name of users who are above age of 18

#rails #db