Permalink
Browse files

avoid creating so many Arel::Table objects

  • Loading branch information...
1 parent 9f1b0b3 commit 90171ad833fa15a3030e15b7eb2043e1204d9db0 @tenderlove tenderlove committed Jan 5, 2011
@@ -2,17 +2,24 @@ 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
@reflection.reset_column_information
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 @@ def construct_joins
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

0 comments on commit 90171ad

Please sign in to comment.