aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorEmilio Tagua <miloops@gmail.com>2009-08-18 16:28:04 -0300
committerEmilio Tagua <miloops@gmail.com>2009-08-18 16:28:04 -0300
commitfefb4c78ac8f37ea0b14cbb0c008f305a1bbd36f (patch)
treeceda4f952ae6182a4495a41ca3a6dbc962ee5df8 /activerecord/lib/active_record
parent0d6997b6e3f25d87b08b4aacaa2140609d5cc19c (diff)
downloadrails-fefb4c78ac8f37ea0b14cbb0c008f305a1bbd36f.tar.gz
rails-fefb4c78ac8f37ea0b14cbb0c008f305a1bbd36f.tar.bz2
rails-fefb4c78ac8f37ea0b14cbb0c008f305a1bbd36f.zip
Cache arel_table when possible, use class method arel_table instead
instance method.
Diffstat (limited to 'activerecord/lib/active_record')
-rwxr-xr-xactiverecord/lib/active_record/base.rb17
-rw-r--r--activerecord/lib/active_record/locking/optimistic.rb8
2 files changed, 13 insertions, 12 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 3bbe23865f..c74d8c6190 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -2572,7 +2572,7 @@ module ActiveRecord #:nodoc:
# be made (since they can't be persisted).
def destroy
unless new_record?
- arel_table(true).conditions(arel_table[self.class.primary_key].eq(id)).delete
+ self.class.arel_table(self.class.table_name, true).conditions(self.class.arel_table[self.class.primary_key].eq(id)).delete
end
@destroyed = true
@@ -2867,7 +2867,7 @@ module ActiveRecord #:nodoc:
def update(attribute_names = @attributes.keys)
attributes_with_values = arel_attributes_values(false, false, attribute_names)
return 0 if attributes_with_values.empty?
- arel_table(true).conditions(arel_table[self.class.primary_key].eq(id)).update(attributes_with_values)
+ self.class.arel_table(self.class.table_name, true).conditions(self.class.arel_table[self.class.primary_key].eq(id)).update(attributes_with_values)
end
# Creates a record with values matching those of the instance attributes
@@ -2877,12 +2877,14 @@ module ActiveRecord #:nodoc:
self.id = connection.next_sequence_value(self.class.sequence_name)
end
+ # Reload ARel relation cached table
+ self.class.arel_table(self.class.table_name, true)
attributes_values = arel_attributes_values
new_id = if attributes_values.empty?
- arel_table.insert connection.empty_insert_statement_value
+ self.class.arel_table.insert connection.empty_insert_statement_value
else
- arel_table.insert attributes_values
+ self.class.arel_table.insert attributes_values
end
self.id ||= new_id
@@ -2954,11 +2956,6 @@ module ActiveRecord #:nodoc:
default
end
- def arel_table(reload = nil)
- @arel_table = Relation.new(self.class, Arel::Table.new(self.class.table_name)) if reload || @arel_table.nil?
- @arel_table
- end
-
# Returns a copy of the attributes hash where all the values have been safely quoted for use in
# an SQL statement.
def attributes_with_quotes(include_primary_key = true, include_readonly_attributes = true, attribute_names = @attributes.keys)
@@ -2992,7 +2989,7 @@ module ActiveRecord #:nodoc:
if value && ((self.class.serialized_attributes.has_key?(name) && (value.acts_like?(:date) || value.acts_like?(:time))) || value.is_a?(Hash) || value.is_a?(Array))
value = value.to_yaml
end
- attrs[arel_table[name]] = value
+ attrs[self.class.arel_table[name]] = value
end
end
end
diff --git a/activerecord/lib/active_record/locking/optimistic.rb b/activerecord/lib/active_record/locking/optimistic.rb
index 4e833ec871..c8cd79a2b0 100644
--- a/activerecord/lib/active_record/locking/optimistic.rb
+++ b/activerecord/lib/active_record/locking/optimistic.rb
@@ -89,7 +89,9 @@ module ActiveRecord
attribute_names.uniq!
begin
- affected_rows = arel_table(true).where(
+ arel_table = self.class.arel_table(self.class.table_name)
+
+ affected_rows = arel_table.where(
arel_table[self.class.primary_key].eq(quoted_id).and(
arel_table[self.class.locking_column].eq(quote_value(previous_value))
)
@@ -116,7 +118,9 @@ module ActiveRecord
lock_col = self.class.locking_column
previous_value = send(lock_col).to_i
- affected_rows = arel_table(true).where(
+ arel_table = self.class.arel_table(self.class.table_name)
+
+ affected_rows = arel_table.where(
arel_table[self.class.primary_key].eq(quoted_id).and(
arel_table[self.class.locking_column].eq(quote_value(previous_value))
)