diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-01-05 10:29:06 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-01-05 10:29:06 -0800 |
commit | 90171ad833fa15a3030e15b7eb2043e1204d9db0 (patch) | |
tree | 7c35ce08409767c0d081b14d01008f47df1ce7a3 /activerecord/lib/active_record/associations | |
parent | 9f1b0b32e27af668014c6fb21edbfc869f36dd2d (diff) | |
download | rails-90171ad833fa15a3030e15b7eb2043e1204d9db0.tar.gz rails-90171ad833fa15a3030e15b7eb2043e1204d9db0.tar.bz2 rails-90171ad833fa15a3030e15b7eb2043e1204d9db0.zip |
avoid creating so many Arel::Table objects
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r-- | activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb | 15 |
1 files changed, 9 insertions, 6 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 3c939d7e85..b18ec23037 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 @@ -2,9 +2,16 @@ module ActiveRecord # = Active Record Has And Belongs To Many Association module Associations class HasAndBelongsToManyAssociation < AssociationCollection #:nodoc: + attr_reader :join_table + + def initialize(owner, reflection) + @join_table_name = reflection.options[:join_table] + @join_table = Arel::Table.new(@join_table_name) + super + end def columns - @reflection.columns(@reflection.options[:join_table], "#{@reflection.options[:join_table]} Columns") + @reflection.columns(@join_table_name, "#{@join_table_name} Columns") end def reset_column_information @@ -12,7 +19,7 @@ module ActiveRecord end def has_primary_key? - @has_primary_key ||= @owner.connection.supports_primary_key? && @owner.connection.primary_key(@reflection.options[:join_table]) + @has_primary_key ||= @owner.connection.supports_primary_key? && @owner.connection.primary_key(@join_table_name) end protected @@ -77,10 +84,6 @@ module ActiveRecord right.create_join(right, right.create_on(condition)) end - def join_table - Arel::Table.new(@reflection.options[:join_table]) - end - def construct_owner_conditions super(join_table) end |