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

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -