diff options
Diffstat (limited to 'activerecord/lib')
5 files changed, 8 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/associations/alias_tracker.rb b/activerecord/lib/active_record/associations/alias_tracker.rb index 44e2ee141e..bd98cf2f46 100644 --- a/activerecord/lib/active_record/associations/alias_tracker.rb +++ b/activerecord/lib/active_record/associations/alias_tracker.rb @@ -49,8 +49,8 @@ module ActiveRecord end end - def pluralize(table_name) - ActiveRecord::Base.pluralize_table_names ? table_name.to_s.pluralize : table_name.to_s + def pluralize(table_name, base) + base.pluralize_table_names ? table_name.to_s.pluralize : table_name.to_s end private 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 1ca448236e..198ad06360 100644 --- a/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb +++ b/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb @@ -19,7 +19,7 @@ module ActiveRecord def klass type = owner[reflection.foreign_type] - type && type.constantize + type.presence && type.constantize end def raise_on_type_mismatch(record) diff --git a/activerecord/lib/active_record/associations/join_helper.rb b/activerecord/lib/active_record/associations/join_helper.rb index eae546e76e..87e33891a5 100644 --- a/activerecord/lib/active_record/associations/join_helper.rb +++ b/activerecord/lib/active_record/associations/join_helper.rb @@ -32,7 +32,7 @@ module ActiveRecord end def table_alias_for(reflection, join = false) - name = alias_tracker.pluralize(reflection.name) + name = alias_tracker.pluralize(reflection.name, reflection.active_record) name << "_#{alias_suffix}" name << "_join" if join name diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index dd5b9a00ff..19a7965429 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -393,8 +393,8 @@ module ActiveRecord #:nodoc: # Indicates whether table names should be the pluralized versions of the corresponding class names. # If true, the default table name for a Product class will be +products+. If false, it would just be +product+. # See table_name for the full rules on table/class naming. This is true, by default. - cattr_accessor :pluralize_table_names, :instance_writer => false - @@pluralize_table_names = true + class_attribute :pluralize_table_names, :instance_writer => false + self.pluralize_table_names = true ## # :singleton-method: diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index 475e4338ca..4659563f33 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -264,6 +264,7 @@ module ActiveRecord end def find_or_instantiator_by_attributes(match, attributes, *args) + options = args.size > 1 && args.last(2).all?{ |a| a.is_a?(Hash) } ? args.extract_options! : {} protected_attributes_for_create, unprotected_attributes_for_create = {}, {} args.each_with_index do |arg, i| if arg.is_a?(Hash) @@ -278,8 +279,7 @@ module ActiveRecord record = where(conditions).first unless record - record = @klass.new do |r| - r.assign_attributes(protected_attributes_for_create) + record = @klass.new(protected_attributes_for_create, options) do |r| r.assign_attributes(unprotected_attributes_for_create, :without_protection => true) end yield(record) if block_given? |