Rails 3 Joins -- Select only certain columns
You could use something like this:
@comments = Comment.joins(:user)
.select("comments.*, users.first_name")
.where(study_id: @study.id)
Ruby rails - select only few columns from the data base
Rails 3:
Item.select("name, address").where( .... )
Rails query - How to joins two tables on specific columns
Breaking the parts out for clarity.
The tables involved...
account_table = Account.arel_table
transfership_table = OwnershipTransfer.arel_table
The arel join...
join = account_table.join(transfership_table).on(account_table[id].eq( transfership_table[:transfer_from_id] ))
Using the arel join in the query...
Account.joins(join.join_sources).where(ownership_transfers: {meeting_event_id: 458})
in Rails how to select additional columns from multiple tables
result = User.first.usertags.joins(:tag).select("tags.name as tag_name, tags.id, usertags.id, user.id")
result.collect{|r| r.tag_name}
Related Topics
Weird Rails Error "Permission Denied: Bin/Rails" for Old Rails Apps
Using Yield Inside Define_Method in Ruby
How Would I Go About Programmatically Interacting with VSt(I) Plugins to Synthesize Audio
Why Do I Get an "Undefined Method for 'Has_Attached_File' When Installing Paperclip
How to Turn a Ruby Method into a Block
Devise Skip_Confirmation! Fails to Avoid to Send the Confirmation Instructions
Ruby Regex- Does Gsub Store What It Matches
Heroku: No Rakefile Found (But Works Locally)
How to Get an Empty Temporary Directory in Ruby on Rails
Rails 4.1 Can't Deploy via Capistrano 3
What's the Difference Between Arrays and Hashes
How to Authorize a Google Service Account Without the Default Credentials File
How to Get Ruby to Parse Time as If It Were in a Different Time Zone
Nokogiri To_Xml Without Carriage Returns
Why Is This Permissions Error Occurring with Mod_Passenger.So