diff options
author | Neeraj Singh <neerajdotname@gmail.com> | 2010-08-12 21:37:48 -0400 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-08-19 14:52:15 -0300 |
commit | 2e455429427a4078d2888cc39305f951bdf1e643 (patch) | |
tree | b67aa66e66704aca116fd90f72144528aab563b4 /activerecord/lib/active_record/associations | |
parent | 43f44c1a034497fef0a9ed64e0da6f090b5c3b7e (diff) | |
download | rails-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/associations')
-rw-r--r-- | activerecord/lib/active_record/associations/association_collection.rb | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index b5159eead3..132e9cf882 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -492,7 +492,12 @@ module ActiveRecord def create_record(attrs) attrs.update(@reflection.options[:conditions]) if @reflection.options[:conditions].is_a?(Hash) ensure_owner_is_not_new - record = @reflection.klass.send(:with_scope, :create => construct_scope[:create]) do + + _scope = self.construct_scope[:create] + csm = @reflection.klass.send(:current_scoped_methods) + options = (csm.blank? || !_scope.is_a?(Hash)) ? _scope : _scope.merge(csm.where_values_hash) + + record = @reflection.klass.send(:with_scope, :create => options) do @reflection.build_association(attrs) end if block_given? |