diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-02-14 11:51:56 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-02-14 11:51:56 -0800 |
commit | 0123ceb9cd1ae352308184852cae1edbd62155e1 (patch) | |
tree | e52d0c9c4fdca1f5e263e38faa10877eaa3190ec /activerecord/lib/active_record/associations/association_proxy.rb | |
parent | 6f4e3ffd0f42c92a00536e7e1356be3e8cf37639 (diff) | |
parent | b9ea751d0e56bd00d341766977a607ed3f7ddd0f (diff) | |
download | rails-0123ceb9cd1ae352308184852cae1edbd62155e1.tar.gz rails-0123ceb9cd1ae352308184852cae1edbd62155e1.tar.bz2 rails-0123ceb9cd1ae352308184852cae1edbd62155e1.zip |
Merge remote branch 'jonleighton/association_fixes'
* jonleighton/association_fixes:
Add a transaction wrapper in add_to_target. This means that #build will now also use a transaction. IMO this is reasonable given that the before_add and after_add callbacks might do anything, and this great consistency allows us to abstract out the duplicate code from #build and #create.
Inline ensure_owner_is_persisted! as it is only called from one place
@target should always be an array
Rename add_record_to_target_with_callbacks to add_to_target
Don't pass the block through build_record
Move create and create! next to build
Get rid of create_record as it is not only used in one place
Get rid of AssociationCollection#save_record
Fix test/cases/connection_pool_test.rb for sqlite3 in-memory db
Add interpolation of association conditions back in, in the form of proc { ... } rather than instance_eval-ing strings
Diffstat (limited to 'activerecord/lib/active_record/associations/association_proxy.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/association_proxy.rb | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/associations/association_proxy.rb b/activerecord/lib/active_record/associations/association_proxy.rb index 2832f49c23..fc03a4b619 100644 --- a/activerecord/lib/active_record/associations/association_proxy.rb +++ b/activerecord/lib/active_record/associations/association_proxy.rb @@ -184,7 +184,8 @@ module ActiveRecord def association_scope scope = target_klass.unscoped scope = scope.create_with(creation_attributes) - scope = scope.apply_finder_options(@reflection.options.slice(:conditions, :readonly, :include)) + scope = scope.apply_finder_options(@reflection.options.slice(:readonly, :include)) + scope = scope.where(interpolate(@reflection.options[:conditions])) if select = select_value scope = scope.select(select) end @@ -240,8 +241,12 @@ module ActiveRecord !loaded? && (!@owner.new_record? || foreign_key_present?) && target_klass end - def interpolate_sql(sql, record = nil) - @owner.send(:interpolate_sql, sql, record) + def interpolate(sql, record = nil) + if sql.respond_to?(:to_proc) + @owner.send(:instance_exec, record, &sql) + else + sql + end end def select_value |