when you want to limit which columns are retrieved using select
How do I control the columns of the relevant model as well?
Post>--Category
I only want to get title
for Post
and name
for Category
.
Image
Post.select(:title,:category=>name)
Post>-<Tag
I only want to get title
for Post
and Tag
name.
Image
Post.select(:title,:tags=>name)
Post.joins(:category).select('posts.title, categories.name')
Post.joins(:tag).select('posts.title, tags.name')
You can use a string instead of a key.
© 2024 OneMinuteCode. All rights reserved.