diff options
author | Bogdan Gusiev <agresso@gmail.com> | 2011-11-30 11:03:00 +0200 |
---|---|---|
committer | Bogdan Gusiev <agresso@gmail.com> | 2011-11-30 11:03:00 +0200 |
commit | a382d60f6abc94b6a965525872f858e48abc00de (patch) | |
tree | 969d8b7d6321f7868e2f613f6f44987f3f471911 /railties/guides | |
parent | d9c288207731e61c40ce6276fd91f0b800d3fabb (diff) | |
download | rails-a382d60f6abc94b6a965525872f858e48abc00de.tar.gz rails-a382d60f6abc94b6a965525872f858e48abc00de.tar.bz2 rails-a382d60f6abc94b6a965525872f858e48abc00de.zip |
ActiveRecord::Relation#pluck method
Diffstat (limited to 'railties/guides')
-rw-r--r-- | railties/guides/source/active_record_querying.textile | 9 |
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+. |