aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2012-09-12 14:04:11 -0700
committerJon Leighton <j@jonathanleighton.com>2012-09-12 14:04:11 -0700
commitb5aed34c442550c4caad1fdca12c921d5ab9840f (patch)
treee19d1e7147070f25fcd18754211913552f99dde1 /guides/source
parent0f228b420e26584e26702935135a4b099df85696 (diff)
parent3da275c4396d7fad250d2b786027ba4f14344bd4 (diff)
downloadrails-b5aed34c442550c4caad1fdca12c921d5ab9840f.tar.gz
rails-b5aed34c442550c4caad1fdca12c921d5ab9840f.tar.bz2
rails-b5aed34c442550c4caad1fdca12c921d5ab9840f.zip
Merge pull request #7273 from beerlington/foreign_key_model_queries
Convert model name to foreign key in queries
Diffstat (limited to 'guides/source')
-rw-r--r--guides/source/active_record_querying.textile7
1 files changed, 7 insertions, 0 deletions
diff --git a/guides/source/active_record_querying.textile b/guides/source/active_record_querying.textile
index 96ae5b2972..e21b86721f 100644
--- a/guides/source/active_record_querying.textile
+++ b/guides/source/active_record_querying.textile
@@ -465,6 +465,13 @@ The field name can also be a string:
Client.where('locked' => true)
</ruby>
+In the case of a belongs_to relationship, an association key can be used to specify the model if an ActiveRecord object is used as the value. This method works with polymorphic relationships as well.
+
+<ruby>
+Post.where(:author => author)
+Author.joins(:posts).where(:posts => {:author => author})
+</ruby>
+
NOTE: The values cannot be symbols. For example, you cannot do +Client.where(:status => :active)+.
h5(#hash-range_conditions). Range Conditions