diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2011-03-29 15:08:40 +0100 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2011-03-29 17:21:21 +0100 |
commit | a9dafbb28de3e34c31ebf184fbc4e2042c7ff207 (patch) | |
tree | c203ba38afca1b4d521ef1ce0de513a27f49aa5c /railties/guides/source/active_record_querying.textile | |
parent | e8d20b858d004e26c3b8c25aae099fce2eca6857 (diff) | |
download | rails-a9dafbb28de3e34c31ebf184fbc4e2042c7ff207.tar.gz rails-a9dafbb28de3e34c31ebf184fbc4e2042c7ff207.tar.bz2 rails-a9dafbb28de3e34c31ebf184fbc4e2042c7ff207.zip |
Delegate first!, last!, any? and many? to scoped
Diffstat (limited to 'railties/guides/source/active_record_querying.textile')
-rw-r--r-- | railties/guides/source/active_record_querying.textile | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index 2c5d9e67e3..f3a10b8b92 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -962,6 +962,26 @@ Client.exists? The above returns +false+ if the +clients+ table is empty and +true+ otherwise. +You can also use +any?+ and +many?+ to check for existence on a model or relation. + +<ruby> +# via a model +Post.any? +Post.many? + +# via a named scope +Post.recent.any? +Post.recent.many? + +# via a relation +Post.where(:published => true).any? +Post.where(:published => true).many? + +# via an association +Post.first.categories.any? +Post.first.categories.many? +</ruby> + h3. Calculations This section uses count as an example method in this preamble, but the options described apply to all sub-sections. |