aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source/active_record_querying.textile
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-11-30 01:41:09 -0800
committerJon Leighton <j@jonathanleighton.com>2011-11-30 01:41:09 -0800
commit271308cb9617b86cd4de20b629be504b48aea537 (patch)
treed713dd695abdcb09f1c191f1844166a27bf8ba38 /railties/guides/source/active_record_querying.textile
parent38ab982cfff98570b5f12933cff489364845789c (diff)
parenta382d60f6abc94b6a965525872f858e48abc00de (diff)
downloadrails-271308cb9617b86cd4de20b629be504b48aea537.tar.gz
rails-271308cb9617b86cd4de20b629be504b48aea537.tar.bz2
rails-271308cb9617b86cd4de20b629be504b48aea537.zip
Merge pull request #1915 from bogdan/active_record_map
ActiveRecord::Base.map method for direct select by single column
Diffstat (limited to 'railties/guides/source/active_record_querying.textile')
-rw-r--r--railties/guides/source/active_record_querying.textile9
1 files changed, 9 insertions, 0 deletions
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile
index c4724f182e..073f7c143d 100644
--- a/railties/guides/source/active_record_querying.textile
+++ b/railties/guides/source/active_record_querying.textile
@@ -1146,6 +1146,15 @@ h3. +select_all+
Client.connection.select_all("SELECT * FROM clients WHERE id = '1'")
</ruby>
+h3. +pluck+
+
+<tt>pluck</tt> can be used to query single column from table under model. It accepts column name as argument and returns Array of values of the specified column with corresponding data type.
+
+<ruby>
+Client.where(:active => true).pluck(:id) # SELECT id FROM clients WHERE clients.active
+Client.uniq.pluck(:role) # SELECT DISTINCT role FROM clients
+</ruby>
+
h3. Existence of Objects
If you simply want to check for the existence of the object there's a method called +exists?+. This method will query the database using the same query as +find+, but instead of returning an object or collection of objects it will return either +true+ or +false+.