aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-11-19 11:16:12 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-11-19 11:16:12 +0000
commit02adc49d72152a00a93423931f767f9cdb0ef15a (patch)
treeaa4adb878d5bdb0e26db3aaf0cb0c6e705b2c5dc /activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
parentae8171ddc5886102421e356888f03d06e7bf5131 (diff)
downloadrails-02adc49d72152a00a93423931f767f9cdb0ef15a.tar.gz
rails-02adc49d72152a00a93423931f767f9cdb0ef15a.tar.bz2
rails-02adc49d72152a00a93423931f767f9cdb0ef15a.zip
Simplify association proxy implementation by factoring construct_scope out of method_missing. Closes #6643.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5564 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb')
-rw-r--r--activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb14
1 files changed, 4 insertions, 10 deletions
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 1eea798ab4..c8e216f072 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
@@ -86,16 +86,6 @@ module ActiveRecord
alias :concat_with_attributes :push_with_attributes
protected
- def method_missing(method, *args, &block)
- if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method))
- super
- else
- @reflection.klass.with_scope(:find => { :conditions => @finder_sql, :joins => @join_sql, :readonly => false }) do
- @reflection.klass.send(method, *args, &block)
- end
- end
- end
-
def count_records
load_target.size
end
@@ -158,6 +148,10 @@ module ActiveRecord
@join_sql = "INNER JOIN #{@reflection.options[:join_table]} ON #{@reflection.klass.table_name}.#{@reflection.klass.primary_key} = #{@reflection.options[:join_table]}.#{@reflection.association_foreign_key}"
end
+ def construct_scope
+ { :find => { :conditions => @finder_sql, :joins => @join_sql, :readonly => false } }
+ end
+
# Join tables with additional columns on top of the two foreign keys must be considered ambigious unless a select
# clause has been explicitly defined. Otherwise you can get broken records back, if, say, the join column also has
# and id column, which will then overwrite the id column of the records coming back.