Browse files

String interpolation conditions

  • Loading branch information...
1 parent 5a1fe90 commit 67f30fd9639409877a57a7ba758cd13496433d69 @lifo lifo committed Apr 23, 2009
Showing with 11 additions and 0 deletions.
  1. +11 −0 railties/guides/source/association_basics.textile
11 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 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:
+class Customer < ActiveRecord::Base
+ has_many :latest_orders, :class_name => "Order",
+ :conditions => 'orders.created_at > #{10.hours.ago.to_s(:db).inspect}'
+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.

0 comments on commit 67f30fd

Please sign in to comment.