From 8713bb6ab8ff5acf60872b0b8f0bffd13a0aa1ca Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Thu, 23 Dec 2010 18:36:39 +1000 Subject: Query guide: cover further ARel methods --- .../guides/source/active_record_querying.textile | 83 ++++++++++++++++++++-- 1 file changed, 76 insertions(+), 7 deletions(-) (limited to 'railties/guides/source/active_record_querying.textile') diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index 1bd9ec7972..8eb28ec953 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -355,38 +355,107 @@ The +eq+ method can be used to check if a field is a specific value: Post.where(Post.arel_table[:comments_count].eq(5)) +This method's opposite is +not_eq+. + h4. +eq_any+ -The +eq_any+ method can be used to return objects of a relation that have the specified field matching any of the specified values. +Checks if the specified field matches any of the given values. Post.where(Post.arel_table[:comments_count].eq_any([1,2]) +This method's opposite is +not_eq_any+. + h4. +in+ -To check if a value is within a given group of values, use the +in+ method: +To check if a field is within a given group of values, use the +in+ method: - Post.where(Post.arel_table[:id].in([1,2,3])) +Post.where(Post.arel_table[:id].in([1,2,3])) +This method's opposite is +not_in+. + h4. +in_any+ -Check if a value is within any one of a group of values: +Check if a field is within any one of a group of values: - Post.where(Post.arel_table[:id]).in_any([1,2,3], [4,5,6]) +Post.where(Post.arel_table[:id]).in_any([1,2,3], [4,5,6]) +This method's opposite is +not_in_any+. + h4. +in_all+ -Check if a value is within all of the specified groups of values: +Check if a field is within all of the specified groups of values: + + +Post.where(Post.arel_table[:id]).in_all([1,2,3], [1,4,6]) + + +This method's opposite is +not_in_all+. + +h4. +matches+ + +Match a specific field with a given value. Use +%+ for wildcard searching. + + +Post.where(Post.arel_table[:author].matches("Ryan%")) + + +This method's opposite is +does_not_match+. + +h4. +matches_any+ + +Match a specific field with any given value. Use +%+ for wildcard searching. + + +Post.where(Post.arel_table[:author].matches_any(["Ryan%", "Yehuda%"])) + + +This method's opposite is +does_not_match_any+ + +h4. +matches_all+ + +Match a specific field with all given values. Use +%+ for wild card searching. + + +Post.where(Post.arel_table[:author].matches_all(["Ryan%", "%Bigg"])) + + +This method's opposite is +does_not_match_all+. + +h4. +gteq+ + +Check for a field greater than or equal to a specific value. + + +Post.where(Post.arel_table[:comments_count].gteq(1)) + + +This method's opposite is +lteq+. + +h4. +gteq_any+ + +Check for a field greater than or equal to any of the given values. + + +Post.where(Post.arel_table[:comments_count].gteq_any([1,2])) + + +This method's opposite is +lteq_any+. + +h4. +gteq_all+ + +Check for a field greater than or equal to all of the given values. - Post.where(Post.arel_table[:id]).in_all([1,2,3], [1,4,6]) +Post.where(Post.arel_table[:comments_count].gteq_all([1,2])) +This method's opposite is +lteq_all+. h3. Ordering -- cgit v1.2.3