From 38218929e9b3205a2a731660b3c5527937e1c015 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Thu, 26 Feb 2015 12:40:22 -0700 Subject: Properly create through records when called with `where` Various behaviors needed by associations (such as creating the through record) are lost when `where` is called, since we stop having a `CollectionProxy` and start having an `AssociationRelation` which does not contain this behavior. I *think* we should be able to rm `AssociationRelation`, but we have tests saying the changes required to do that would be bad (Without saying why. Of course. >_>) Fixes #19073. --- activerecord/lib/active_record/association_relation.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'activerecord/lib/active_record/association_relation.rb') diff --git a/activerecord/lib/active_record/association_relation.rb b/activerecord/lib/active_record/association_relation.rb index f2b44913db..ee0bb8fafe 100644 --- a/activerecord/lib/active_record/association_relation.rb +++ b/activerecord/lib/active_record/association_relation.rb @@ -13,6 +13,19 @@ module ActiveRecord other == to_a end + def build(*args, &block) + scoping { @association.build(*args, &block) } + end + alias new build + + def create(*args, &block) + scoping { @association.create(*args, &block) } + end + + def create!(*args, &block) + scoping { @association.create!(*args, &block) } + end + private def exec_queries -- cgit v1.2.3