mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Create is now powered by Arel. Removed methods that are no longer used.
This commit is contained in:
parent
0f5785c997
commit
260c847817
4 changed files with 20 additions and 19 deletions
|
@ -2907,18 +2907,13 @@ module ActiveRecord #:nodoc:
|
||||||
self.id = connection.next_sequence_value(self.class.sequence_name)
|
self.id = connection.next_sequence_value(self.class.sequence_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
quoted_attributes = attributes_with_quotes
|
new_id = if arel_attributes_values.empty?
|
||||||
|
arel_table.insert connection.empty_insert_statement_value
|
||||||
statement = if quoted_attributes.empty?
|
|
||||||
connection.empty_insert_statement(self.class.table_name)
|
|
||||||
else
|
else
|
||||||
"INSERT INTO #{self.class.quoted_table_name} " +
|
arel_table.insert arel_attributes_values
|
||||||
"(#{quoted_column_names.join(', ')}) " +
|
|
||||||
"VALUES(#{quoted_attributes.values.join(', ')})"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
self.id = connection.insert(statement, "#{self.class.name} Create",
|
self.id ||= new_id
|
||||||
self.class.primary_key, self.id, self.class.sequence_name)
|
|
||||||
|
|
||||||
@new_record = false
|
@new_record = false
|
||||||
id
|
id
|
||||||
|
@ -2987,6 +2982,10 @@ module ActiveRecord #:nodoc:
|
||||||
default
|
default
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def arel_table
|
||||||
|
@arel_table = Arel::Table.new(self.class.table_name)
|
||||||
|
end
|
||||||
|
|
||||||
# Returns a copy of the attributes hash where all the values have been safely quoted for use in
|
# Returns a copy of the attributes hash where all the values have been safely quoted for use in
|
||||||
# an SQL statement.
|
# an SQL statement.
|
||||||
def attributes_with_quotes(include_primary_key = true, include_readonly_attributes = true, attribute_names = @attributes.keys)
|
def attributes_with_quotes(include_primary_key = true, include_readonly_attributes = true, attribute_names = @attributes.keys)
|
||||||
|
@ -3007,10 +3006,8 @@ module ActiveRecord #:nodoc:
|
||||||
include_readonly_attributes ? quoted : remove_readonly_attributes(quoted)
|
include_readonly_attributes ? quoted : remove_readonly_attributes(quoted)
|
||||||
end
|
end
|
||||||
|
|
||||||
def arel_table
|
# Returns a copy of the attributes hash where all the values have been safely quoted for use in
|
||||||
@arel_table = Arel::Table.new(self.class.table_name)
|
# an Arel insert/update method.
|
||||||
end
|
|
||||||
|
|
||||||
def arel_attributes_values(include_primary_key = true, include_readonly_attributes = true, attribute_names = @attributes.keys)
|
def arel_attributes_values(include_primary_key = true, include_readonly_attributes = true, attribute_names = @attributes.keys)
|
||||||
attrs = {}
|
attrs = {}
|
||||||
connection = self.class.connection
|
connection = self.class.connection
|
||||||
|
@ -3019,7 +3016,11 @@ module ActiveRecord #:nodoc:
|
||||||
value = read_attribute(name)
|
value = read_attribute(name)
|
||||||
|
|
||||||
if include_readonly_attributes || (!include_readonly_attributes && !self.class.readonly_attributes.include?(name))
|
if include_readonly_attributes || (!include_readonly_attributes && !self.class.readonly_attributes.include?(name))
|
||||||
attrs[arel_table[name]] = value.is_a?(Hash) ? value.to_yaml : value
|
# We need explicit to_yaml because quote() does not properly convert Time/Date fields to YAML.
|
||||||
|
if value && self.class.serialized_attributes.has_key?(name) && (value.acts_like?(:date) || value.acts_like?(:time))
|
||||||
|
value = value.to_yaml
|
||||||
|
end
|
||||||
|
attrs[arel_table[name]] = (value.is_a?(Hash) || value.is_a?(Array)) ? value.to_yaml : value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -208,8 +208,8 @@ module ActiveRecord
|
||||||
execute "INSERT INTO #{quote_table_name(table_name)} (#{fixture.key_list}) VALUES (#{fixture.value_list})", 'Fixture Insert'
|
execute "INSERT INTO #{quote_table_name(table_name)} (#{fixture.key_list}) VALUES (#{fixture.value_list})", 'Fixture Insert'
|
||||||
end
|
end
|
||||||
|
|
||||||
def empty_insert_statement(table_name)
|
def empty_insert_statement_value
|
||||||
"INSERT INTO #{quote_table_name(table_name)} VALUES(DEFAULT)"
|
"VALUES(DEFAULT)"
|
||||||
end
|
end
|
||||||
|
|
||||||
def case_sensitive_equality_operator
|
def case_sensitive_equality_operator
|
||||||
|
|
|
@ -308,8 +308,8 @@ module ActiveRecord
|
||||||
alter_table(table_name, :rename => {column_name.to_s => new_column_name.to_s})
|
alter_table(table_name, :rename => {column_name.to_s => new_column_name.to_s})
|
||||||
end
|
end
|
||||||
|
|
||||||
def empty_insert_statement(table_name)
|
def empty_insert_statement_value
|
||||||
"INSERT INTO #{table_name} VALUES(NULL)"
|
"VALUES(NULL)"
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
2
arel
2
arel
|
@ -1 +1 @@
|
||||||
Subproject commit 97811698ab0e68b33fbf3067c3764e385dd75d53
|
Subproject commit 808b9e90a38c6c19e109da8eb5f2a264fd780d9a
|
Loading…
Reference in a new issue