ruby on rails - Access columns from two different tables -


i using rails 4.2. have model user , comment

class user   has_many :comments end  class comment   belongs_to :user end 

user has column name , comment has column user_id , content want fetch columns comment.content , user.name using join can this

comment.joins(:user).select(:name,:content) 

can suggest efficient method perform action?

you can namespace columns following:

comment.joins(:user).pluck('users.name', 'comments.content')  # though, don't need `comments.content`; `content` work well. 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -