diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-12-13 00:39:51 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-12-13 00:39:51 +0000 |
commit | e5d9ad3e2903597e708fcb3ad76f08b4a600d82d (patch) | |
tree | c677481cd60c2af38655fbcb5d6d71efd9cf126e /activerecord/lib/active_record/associations | |
parent | f7e39c4ec78e81c4336a1ef470f3ff0a2430fc7a (diff) | |
download | rails-e5d9ad3e2903597e708fcb3ad76f08b4a600d82d.tar.gz rails-e5d9ad3e2903597e708fcb3ad76f08b4a600d82d.tar.bz2 rails-e5d9ad3e2903597e708fcb3ad76f08b4a600d82d.zip |
Added option inheritance for find calls on has_and_belongs_to_many and has_many assosociations [DHH] Added option to specify :group, :limit, :offset, and :select options from find on has_and_belongs_to_many and has_many assosociations [DHH]
Added form_remote_for (form_for meets form_remote_tag) [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3287 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/associations')
4 files changed, 24 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/associations/association_proxy.rb b/activerecord/lib/active_record/associations/association_proxy.rb index 75f9184aa2..c62c042ab2 100644 --- a/activerecord/lib/active_record/associations/association_proxy.rb +++ b/activerecord/lib/active_record/associations/association_proxy.rb @@ -73,6 +73,17 @@ module ActiveRecord def extract_options_from_args!(args) @owner.send(:extract_options_from_args!, args) end + + def merge_options_from_reflection!(options) + options.reverse_merge!( + :group => @reflection.options[:group], + :limit => @reflection.options[:limit], + :offset => @reflection.options[:offset], + :joins => @reflection.options[:joins], + :include => @reflection.options[:include], + :select => @reflection.options[:select] + ) + end private def method_missing(method, *args, &block) diff --git a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb index 417b0905f4..5b203dcc57 100644 --- a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb +++ b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb @@ -49,6 +49,8 @@ module ActiveRecord options[:order] = @reflection.options[:order] end + merge_options_from_reflection!(options) + # Pass through args exactly as we received them. args << options @reflection.klass.find(*args) @@ -88,7 +90,7 @@ module ActiveRecord if @reflection.options[:finder_sql] records = @reflection.klass.find_by_sql(@finder_sql) else - records = find(:all, :include => @reflection.options[:include]) + records = find(:all) end @reflection.options[:uniq] ? uniq(records) : records diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb index f4a08420b7..5a29ffaa30 100644 --- a/activerecord/lib/active_record/associations/has_many_association.rb +++ b/activerecord/lib/active_record/associations/has_many_association.rb @@ -77,6 +77,8 @@ module ActiveRecord options[:order] = @reflection.options[:order] end + merge_options_from_reflection!(options) + # Pass through args exactly as we received them. args << options @reflection.klass.find(*args) @@ -107,14 +109,7 @@ module ActiveRecord if @reflection.options[:finder_sql] @reflection.klass.find_by_sql(@finder_sql) else - @reflection.klass.find(:all, - :conditions => @finder_sql, - :order => @reflection.options[:order], - :limit => @reflection.options[:limit], - :joins => @reflection.options[:joins], - :include => @reflection.options[:include], - :group => @reflection.options[:group] - ) + find(:all) end end @@ -129,6 +124,10 @@ module ActiveRecord @target = [] and loaded if count == 0 + if @reflection.options[:limit] + count = [ @reflection.options[:limit], count ].min + end + return count end @@ -171,7 +170,7 @@ module ActiveRecord "#{@reflection.klass.table_name}.#{@reflection.options[:as]}_id = #{@owner.quoted_id} AND " + "#{@reflection.klass.table_name}.#{@reflection.options[:as]}_type = '#{ActiveRecord::Base.send(:class_name_of_active_record_descendant, @owner.class).to_s}'" @finder_sql << " AND (#{interpolate_sql(@conditions)})" if @conditions - + else @finder_sql = "#{@reflection.klass.table_name}.#{@reflection.primary_key_name} = #{@owner.quoted_id}" @finder_sql << " AND (#{interpolate_sql(@conditions)})" if @conditions diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb index 9ecd6f059e..f6ac03a3e6 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -16,6 +16,8 @@ module ActiveRecord options[:order] = @reflection.options[:order] end + merge_options_from_reflection!(options) + # Pass through args exactly as we received them. args << options @reflection.klass.find(*args) |