diff options
author | Jon Leighton <j@jonathanleighton.com> | 2012-09-28 17:55:35 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2012-09-28 18:08:14 +0100 |
commit | 144e8691cbfb8bba77f18cfe68d5e7fd48887f5e (patch) | |
tree | 161fc7cc2f7d1905c5ae6a9f761f65fd520116be /activerecord/lib/active_record/attribute_methods.rb | |
parent | f9c63ad56da541fa8fc007c01de64ed623053fd2 (diff) | |
download | rails-144e8691cbfb8bba77f18cfe68d5e7fd48887f5e.tar.gz rails-144e8691cbfb8bba77f18cfe68d5e7fd48887f5e.tar.bz2 rails-144e8691cbfb8bba77f18cfe68d5e7fd48887f5e.zip |
Support for partial inserts.
When inserting new records, only the fields which have been changed
from the defaults will actually be included in the INSERT statement.
The other fields will be populated by the database.
This is more efficient, and also means that it will be safe to
remove database columns without getting subsequent errors in running
app processes (so long as the code in those processes doesn't
contain any references to the removed column).
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods.rb')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods.rb | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index ced15bc330..0aff2562b8 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -207,8 +207,8 @@ module ActiveRecord value end - def arel_attributes_with_values_for_create(pk_attribute_allowed) - arel_attributes_with_values(attributes_for_create(pk_attribute_allowed)) + def arel_attributes_with_values_for_create(attribute_names) + arel_attributes_with_values(attributes_for_create(attribute_names)) end def arel_attributes_with_values_for_update(attribute_names) @@ -242,9 +242,9 @@ module ActiveRecord # Filters out the primary keys, from the attribute names, when the primary # key is to be generated (e.g. the id attribute has no value). - def attributes_for_create(pk_attribute_allowed) - @attributes.keys.select do |name| - column_for_attribute(name) && (pk_attribute_allowed || !pk_attribute?(name)) + def attributes_for_create(attribute_names) + attribute_names.select do |name| + column_for_attribute(name) && !(pk_attribute?(name) && id.nil?) end end |