diff options
author | Carl Lerche <carllerche@mac.com> | 2010-04-02 22:33:57 -0700 |
---|---|---|
committer | Carl Lerche <carllerche@mac.com> | 2010-04-02 22:33:57 -0700 |
commit | 13004d4f849682772060371273fda3312dd3b884 (patch) | |
tree | 914af96637598ba61fb458c5837eb8894a65af29 /activerecord/lib/active_record/reflection.rb | |
parent | 386b7bfd9d78a6d8c8bc7cc4a310df806ad0ba57 (diff) | |
download | rails-13004d4f849682772060371273fda3312dd3b884.tar.gz rails-13004d4f849682772060371273fda3312dd3b884.tar.bz2 rails-13004d4f849682772060371273fda3312dd3b884.zip |
Make the query built by has_many ...., :dependent => :____ lazy since all the information is not really available yet.
Diffstat (limited to 'activerecord/lib/active_record/reflection.rb')
-rw-r--r-- | activerecord/lib/active_record/reflection.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 5e8fc104cb..2a3f3f8713 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -277,6 +277,16 @@ module ActiveRecord !options[:validate].nil? ? options[:validate] : (options[:autosave] == true || macro == :has_many) end + def dependent_conditions(record, base_class) + dependent_conditions = [] + dependent_conditions << "#{primary_key_name} = #{record.send(name).send(:owner_quoted_id)}" + dependent_conditions << "#{options[:as]}_type = '#{base_class.name}'" if options[:as] + dependent_conditions << klass.send(:sanitize_sql, options[:conditions]) if options[:conditions] + dependent_conditions = dependent_conditions.collect {|where| "(#{where})" }.join(" AND ") + dependent_conditions = dependent_conditions.gsub('@', '\@') + dependent_conditions + end + private def derive_class_name class_name = name.to_s.camelize |