aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation.rb
diff options
context:
space:
mode:
authorNeeraj Singh <neerajdotname@gmail.com>2010-08-12 21:37:48 -0400
committerJosé Valim <jose.valim@gmail.com>2010-08-19 14:52:15 -0300
commit2e455429427a4078d2888cc39305f951bdf1e643 (patch)
treeb67aa66e66704aca116fd90f72144528aab563b4 /activerecord/lib/active_record/relation.rb
parent43f44c1a034497fef0a9ed64e0da6f090b5c3b7e (diff)
downloadrails-2e455429427a4078d2888cc39305f951bdf1e643.tar.gz
rails-2e455429427a4078d2888cc39305f951bdf1e643.tar.bz2
rails-2e455429427a4078d2888cc39305f951bdf1e643.zip
While creating a new record using has_many create method default scope of child should be respected.
author.posts.create should take into account default_scope defined on post. [#3939: state:resolved] Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activerecord/lib/active_record/relation.rb')
-rw-r--r--activerecord/lib/active_record/relation.rb11
1 files changed, 7 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index cfe4d23965..03b06205d4 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -316,16 +316,19 @@ module ActiveRecord
@to_sql ||= arel.to_sql
end
- def scope_for_create
- @scope_for_create ||= begin
- @create_with_value || Hash[
- @where_values.find_all { |w|
+ def where_values_hash
+ Hash[@where_values.find_all { |w|
w.respond_to?(:operator) && w.operator == :==
}.map { |where|
[where.operand1.name,
where.operand2.respond_to?(:value) ?
where.operand2.value : where.operand2]
}]
+ end
+
+ def scope_for_create
+ @scope_for_create ||= begin
+ @create_with_value || where_values_hash
end
end