diff options
Diffstat (limited to 'activerecord/lib/active_record/associations')
8 files changed, 26 insertions, 26 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index 97d0ec8ce8..552c1ed06e 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -23,7 +23,7 @@ module ActiveRecord flatten_deeper(records).each do |record| raise_on_type_mismatch(record) callback(:before_add, record) - result &&= insert_record(record) unless @owner.new? + result &&= insert_record(record) unless @owner.new_record? @target << record callback(:after_add, record) end @@ -51,7 +51,7 @@ module ActiveRecord def delete(*records) records = flatten_deeper(records) records.each { |record| raise_on_type_mismatch(record) } - records.reject! { |record| @target.delete(record) if record.new? } + records.reject! { |record| @target.delete(record) if record.new_record? } return if records.empty? @owner.transaction do @@ -91,7 +91,7 @@ module ActiveRecord attributes.collect { |attr| create(attr) } else record = build(attributes) - record.save unless @owner.new? + record.save unless @owner.new_record? record end end @@ -103,7 +103,7 @@ module ActiveRecord if loaded? && !@reflection.options[:uniq] @target.size elsif !loaded? && !@reflection.options[:uniq] && @target.is_a?(Array) - unsaved_records = Array(@target.detect { |r| r.new? }) + unsaved_records = Array(@target.detect { |r| r.new_record? }) unsaved_records.size + count_records else count_records diff --git a/activerecord/lib/active_record/associations/association_proxy.rb b/activerecord/lib/active_record/associations/association_proxy.rb index 5d36c22f66..ac7188d712 100644 --- a/activerecord/lib/active_record/associations/association_proxy.rb +++ b/activerecord/lib/active_record/associations/association_proxy.rb @@ -99,10 +99,10 @@ module ActiveRecord def set_belongs_to_association_for(record) if @reflection.options[:as] - record["#{@reflection.options[:as]}_id"] = @owner.id unless @owner.new? + record["#{@reflection.options[:as]}_id"] = @owner.id unless @owner.new_record? record["#{@reflection.options[:as]}_type"] = @owner.class.base_class.name.to_s else - record[@reflection.primary_key_name] = @owner.id unless @owner.new? + record[@reflection.primary_key_name] = @owner.id unless @owner.new_record? end end @@ -125,7 +125,7 @@ module ActiveRecord end def load_target - if !loaded? and (!@owner.new? || foreign_key_present) + if !loaded? and (!@owner.new_record? || foreign_key_present) @target = find_target end diff --git a/activerecord/lib/active_record/associations/belongs_to_association.rb b/activerecord/lib/active_record/associations/belongs_to_association.rb index 52dd61a47e..1752678cbd 100644 --- a/activerecord/lib/active_record/associations/belongs_to_association.rb +++ b/activerecord/lib/active_record/associations/belongs_to_association.rb @@ -13,7 +13,7 @@ module ActiveRecord counter_cache_name = @reflection.counter_cache_column if record.nil? - if counter_cache_name && @owner[counter_cache_name] && !@owner.new? + if counter_cache_name && @owner[counter_cache_name] && !@owner.new_record? @reflection.klass.decrement_counter(counter_cache_name, @owner[@reflection.primary_key_name]) if @owner[@reflection.primary_key_name] end @@ -21,13 +21,13 @@ module ActiveRecord else raise_on_type_mismatch(record) - if counter_cache_name && !@owner.new? + if counter_cache_name && !@owner.new_record? @reflection.klass.increment_counter(counter_cache_name, record.id) @reflection.klass.decrement_counter(counter_cache_name, @owner[@reflection.primary_key_name]) if @owner[@reflection.primary_key_name] end @target = (AssociationProxy === record ? record.target : record) - @owner[@reflection.primary_key_name] = record.id unless record.new? + @owner[@reflection.primary_key_name] = record.id unless record.new_record? @updated = true end diff --git a/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb b/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb index 0a71fa89c9..9549b959fc 100644 --- a/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb +++ b/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb @@ -7,7 +7,7 @@ module ActiveRecord else @target = (AssociationProxy === record ? record.target : record) - unless record.new? + unless record.new_record? @owner[@reflection.primary_key_name] = record.id @owner[@reflection.options[:foreign_type]] = record.class.base_class.name.to_s end 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 f10c5957f8..8c0e50e38e 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 @@ -19,7 +19,7 @@ module ActiveRecord attributes.collect { |attr| create(attr) } else record = build(attributes) - insert_record(record) unless @owner.new? + insert_record(record) unless @owner.new_record? record end end @@ -75,7 +75,7 @@ module ActiveRecord join_attributes.each { |key, value| record[key.to_s] = value } callback(:before_add, record) - insert_record(record) unless @owner.new? + insert_record(record) unless @owner.new_record? @target << record callback(:after_add, record) @@ -101,7 +101,7 @@ module ActiveRecord end def insert_record(record) - if record.new? + if record.new_record? return false unless record.save end @@ -118,7 +118,7 @@ module ActiveRecord attributes[column.name] = record.quoted_id else if record.attributes.has_key?(column.name) - value = @owner.send(:quote, record[column.name], column) + value = @owner.send(:quote_value, record[column.name], column) attributes[column.name] = value unless value.nil? end end diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb index d4c6bdcada..d3fdcbe02f 100644 --- a/activerecord/lib/active_record/associations/has_many_association.rb +++ b/activerecord/lib/active_record/associations/has_many_association.rb @@ -111,7 +111,7 @@ module ActiveRecord end def load_target - if !@owner.new? || foreign_key_present + if !@owner.new_record? || foreign_key_present begin if !loaded? if @target.is_a?(Array) && @target.any? @@ -184,7 +184,7 @@ module ActiveRecord when @reflection.options[:as] @finder_sql = "#{@reflection.klass.table_name}.#{@reflection.options[:as]}_id = #{@owner.quoted_id} AND " + - "#{@reflection.klass.table_name}.#{@reflection.options[:as]}_type = #{@owner.class.quote @owner.class.base_class.name.to_s}" + "#{@reflection.klass.table_name}.#{@reflection.options[:as]}_type = #{@owner.class.quote_value(@owner.class.base_class.name.to_s)}" @finder_sql << " AND (#{conditions})" if conditions else diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb index e232c650fa..d7ca7b5834 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -49,7 +49,7 @@ module ActiveRecord def <<(*records) return if records.empty? through = @reflection.through_reflection - raise ActiveRecord::HasManyThroughCantAssociateNewRecords.new(@owner, through) if @owner.new? + raise ActiveRecord::HasManyThroughCantAssociateNewRecords.new(@owner, through) if @owner.new_record? load_target @@ -57,7 +57,7 @@ module ActiveRecord klass.transaction do flatten_deeper(records).each do |associate| raise_on_type_mismatch(associate) - raise ActiveRecord::HasManyThroughCantAssociateNewRecords.new(@owner, through) unless associate.respond_to?(:new?) && !associate.new? + raise ActiveRecord::HasManyThroughCantAssociateNewRecords.new(@owner, through) unless associate.respond_to?(:new_record?) && !associate.new_record? @owner.send(@reflection.through_reflection.name).proxy_target << klass.with_scope(:create => construct_join_attributes(associate)) { klass.create! } @target << associate @@ -127,7 +127,7 @@ module ActiveRecord def construct_quoted_owner_attributes(reflection) if as = reflection.options[:as] { "#{as}_id" => @owner.quoted_id, - "#{as}_type" => reflection.klass.quote( + "#{as}_type" => reflection.klass.quote_value( @owner.class.base_class.name.to_s, reflection.klass.columns_hash["#{as}_type"]) } else @@ -164,7 +164,7 @@ module ActiveRecord if @reflection.source_reflection.options[:as] polymorphic_join = "AND %s.%s = %s" % [ @reflection.table_name, "#{@reflection.source_reflection.options[:as]}_type", - @owner.class.quote(@reflection.through_reflection.klass.name) + @owner.class.quote_value(@reflection.through_reflection.klass.name) ] end end diff --git a/activerecord/lib/active_record/associations/has_one_association.rb b/activerecord/lib/active_record/associations/has_one_association.rb index 9e7f281744..4ccd725ebd 100644 --- a/activerecord/lib/active_record/associations/has_one_association.rb +++ b/activerecord/lib/active_record/associations/has_one_association.rb @@ -18,7 +18,7 @@ module ActiveRecord if replace_existing replace(record, true) else - record[@reflection.primary_key_name] = @owner.id unless @owner.new? + record[@reflection.primary_key_name] = @owner.id unless @owner.new_record? self.target = record end @@ -30,11 +30,11 @@ module ActiveRecord unless @target.nil? if dependent? && !dont_save && @target != obj - @target.destroy unless @target.new? + @target.destroy unless @target.new_record? @owner.clear_association_cache else @target[@reflection.primary_key_name] = nil - @target.save unless @owner.new? || @target.new? + @target.save unless @owner.new_record? || @target.new_record? end end @@ -48,7 +48,7 @@ module ActiveRecord @loaded = true - unless @owner.new? or obj.nil? or dont_save + unless @owner.new_record? or obj.nil? or dont_save return (obj.save ? self : false) else return (obj.nil? ? nil : self) @@ -69,7 +69,7 @@ module ActiveRecord when @reflection.options[:as] @finder_sql = "#{@reflection.klass.table_name}.#{@reflection.options[:as]}_id = #{@owner.quoted_id} AND " + - "#{@reflection.klass.table_name}.#{@reflection.options[:as]}_type = #{@owner.class.quote @owner.class.base_class.name.to_s}" + "#{@reflection.klass.table_name}.#{@reflection.options[:as]}_type = #{@owner.class.quote_value(@owner.class.base_class.name.to_s)}" else @finder_sql = "#{@reflection.table_name}.#{@reflection.primary_key_name} = #{@owner.quoted_id}" end |