aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-07-14 07:18:26 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-07-14 07:18:26 +0000
commit6f05696ceb2fe21b735c428c96c228705fc4c6c5 (patch)
treea9748c7035bcdb9cebacbccac206c9c76985da87 /activerecord/lib
parenta7cca4eaa50945a3836099b070a06144dc0b6351 (diff)
downloadrails-6f05696ceb2fe21b735c428c96c228705fc4c6c5.tar.gz
rails-6f05696ceb2fe21b735c428c96c228705fc4c6c5.tar.bz2
rails-6f05696ceb2fe21b735c428c96c228705fc4c6c5.zip
Added :select option to find which can specify a different value than the default *, like find(:all, :select => "first_name, last_name"), if you either only want to select part of the columns or exclude columns otherwise included from a join #1338 [Stefan Kaes]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1830 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-xactiverecord/lib/active_record/base.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index be64c1bbd3..936e61a688 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -315,6 +315,8 @@ module ActiveRecord #:nodoc:
# * <tt>:joins</tt>: An SQL fragment for additional joins like "LEFT JOIN comments ON comments.post_id = id". (Rarely needed).
# * <tt>:include</tt>: Names associations that should be loaded alongside using LEFT OUTER JOINs. The symbols named refer
# to already defined associations. See eager loading under Associations.
+ # * <tt>:select</tt>: By default, this is * as in SELECT * FROM, but can be changed if you for example want to do a join, but not
+ # include the joined columns.
#
# Examples for find by id:
# Person.find(1) # returns the object for ID = 1
@@ -739,7 +741,7 @@ module ActiveRecord #:nodoc:
end
def construct_finder_sql(options)
- sql = "SELECT * FROM #{table_name} "
+ sql = "SELECT #{options[:select] || '*'} FROM #{table_name} "
sql << " #{options[:joins]} " if options[:joins]
add_conditions!(sql, options[:conditions])
sql << "ORDER BY #{options[:order]} " if options[:order]