ruby on rails - Includes with only certain attributes -


is there way like:

book.includes(authors: {only: :first_name}) 

i want attribute, not whole author model.

nope, can't. if don't want load data can load books , run separate query on authors bring names alone:

books = book.where(something_here) author_ids = books.map(&:author_id) author_names = author.where(id: author_ids).pluck(:id, :first_name) 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -