I want to find a Blog by its :id, and then select only a couple of its attributes.
Example:
# Doesn't work and I don't know why
# I want to grab the first blog with this id, and then grab only selected attributes
blog = Blog.find(10).select(:id, :title, :date)
This post suggests to use where instead of find. But to my knowledge where in my scenario is inefficient because it continues searching the database for more matches even after it finds the only record I want to grab.
How can I specify to grab the first record it finds by the id, and then grab only the selected attributes?
blog = Blog.select(:id, :title, :date).find(1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With