aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source/active_record_querying.textile
diff options
context:
space:
mode:
authorRyan Bigg <radarlistener@gmail.com>2010-12-23 16:06:29 +1000
committerRyan Bigg <radarlistener@gmail.com>2010-12-23 16:06:29 +1000
commit578f9711fdb42ca9fc4b8248c494afe755cd1c17 (patch)
treeae03d0f06df3ea739bf81dacbcdf0dbc5d767f8a /railties/guides/source/active_record_querying.textile
parentcef17cd705c3529139fa1fd5bbc0e9c6ae289ba4 (diff)
downloadrails-578f9711fdb42ca9fc4b8248c494afe755cd1c17.tar.gz
rails-578f9711fdb42ca9fc4b8248c494afe755cd1c17.tar.bz2
rails-578f9711fdb42ca9fc4b8248c494afe755cd1c17.zip
Query guide: arel_table, eq and eq_any
Diffstat (limited to 'railties/guides/source/active_record_querying.textile')
-rw-r--r--railties/guides/source/active_record_querying.textile26
1 files changed, 26 insertions, 0 deletions
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile
index 5264477e1c..1da12cbc9b 100644
--- a/railties/guides/source/active_record_querying.textile
+++ b/railties/guides/source/active_record_querying.textile
@@ -337,6 +337,32 @@ This code will generate SQL like this:
SELECT * FROM clients WHERE (clients.orders_count IN (1,3,5))
</sql>
+h4. +arel_table+
+
+The +arel_table+ method is used in the following sections to gain access to more advanced functionality of the Active Relation building language. You may see examples such as this:
+
+<ruby>
+Post.where(Post.arel_table[:comments_count].eq(5)))
+</ruby>
+
+Don't be alarmed! This method returns an +Arel::Table+ object which provides methods for accessing fields and building queries, as you'll see in the following sections.
+
+h4. +eq+
+
+The +eq+ method can be used to check if a field is a specific value:
+
+<ruby>
+Post.where(Post.arel_table[:comments_count].eq(5))
+</ruby>
+
+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.
+
+<ruby>
+Post.where(Post.arel_table[:comments_count].eq_any([1,2])
+</ruby>
+
h3. Ordering
To retrieve records from the database in a specific order, you can use the +order+ method.