aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-04-23 14:25:35 +0100
committerPratik Naik <pratiknaik@gmail.com>2009-04-23 14:25:35 +0100
commit67f30fd9639409877a57a7ba758cd13496433d69 (patch)
tree1c1cbe96380b984e52d010d70a4152263d75d726 /railties/guides
parent5a1fe9039b33414b7088813712e03bbe38567cff (diff)
downloadrails-67f30fd9639409877a57a7ba758cd13496433d69.tar.gz
rails-67f30fd9639409877a57a7ba758cd13496433d69.tar.bz2
rails-67f30fd9639409877a57a7ba758cd13496433d69.zip
String interpolation conditions
Diffstat (limited to 'railties/guides')
-rw-r--r--railties/guides/source/association_basics.textile11
1 files changed, 11 insertions, 0 deletions
diff --git a/railties/guides/source/association_basics.textile b/railties/guides/source/association_basics.textile
index 4d75fb6dc4..aaea83fa32 100644
--- a/railties/guides/source/association_basics.textile
+++ b/railties/guides/source/association_basics.textile
@@ -1219,6 +1219,17 @@ end
If you use a hash-style +:conditions+ option, then record creation via this association will be automatically scoped using the hash. In this case, using +@customer.confirmed_orders.create+ or +@customer.confirmed_orders.build+ will create orders where the confirmed column has the value +true+.
+If you need to evaluate conditions dynamically at runtime, you could use string interpolation in single quotes:
+
+<ruby>
+class Customer < ActiveRecord::Base
+ has_many :latest_orders, :class_name => "Order",
+ :conditions => 'orders.created_at > #{10.hours.ago.to_s(:db).inspect}'
+end
+</ruby>
+
+Be sure to use single quotes.
+
h6. +:counter_sql+
Normally Rails automatically generates the proper SQL to count the association members. With the +:counter_sql+ option, you can specify a complete SQL statement to count them yourself.