Skip to content
This repository
Browse code

Merge remote branch 'rails/master'

  • Loading branch information...
commit 5cd3c2a8556c8b1391508508c0f2ddfe89214028 2 parents f17159b + 4a8c880
Xavier Noria fxn authored

Showing 1 changed file with 21 additions and 18 deletions. Show diff stats Hide diff stats

  1. +21 18 activerecord/lib/active_record/base.rb
39 activerecord/lib/active_record/base.rb
@@ -14,6 +14,7 @@
14 14 require 'active_support/core_ext/string/behavior'
15 15 require 'active_support/core_ext/kernel/singleton_class'
16 16 require 'active_support/core_ext/module/delegation'
  17 +require 'active_support/core_ext/module/introspection'
17 18 require 'active_support/core_ext/object/duplicable'
18 19 require 'active_support/core_ext/object/blank'
19 20 require 'arel'
@@ -647,29 +648,14 @@ def table_name
647 648 reset_table_name
648 649 end
649 650
  651 + # Returns a quoted version of the table name, used to construct SQL statements.
650 652 def quoted_table_name
651 653 @quoted_table_name ||= connection.quote_table_name(table_name)
652 654 end
653 655
  656 + # Computes the table name, (re)sets it internally, and returns it.
654 657 def reset_table_name #:nodoc:
655   - base = base_class
656   -
657   - name =
658   - # STI subclasses always use their superclass' table.
659   - unless self == base
660   - base.table_name
661   - else
662   - # Nested classes are prefixed with singular parent table name.
663   - if parent < ActiveRecord::Base && !parent.abstract_class?
664   - contained = parent.table_name
665   - contained = contained.singularize if parent.pluralize_table_names
666   - contained << '_'
667   - end
668   - name = "#{full_table_name_prefix}#{contained}#{undecorated_table_name(base.name)}#{table_name_suffix}"
669   - end
670   -
671   - set_table_name(name)
672   - name
  658 + self.table_name = compute_table_name
673 659 end
674 660
675 661 def full_table_name_prefix #:nodoc:
@@ -1001,6 +987,23 @@ def undecorated_table_name(class_name = base_class.name)
1001 987 table_name
1002 988 end
1003 989
  990 + # Computes and returns a table name according to default conventions.
  991 + def compute_table_name
  992 + base = base_class
  993 + if self == base
  994 + # Nested classes are prefixed with singular parent table name.
  995 + if parent < ActiveRecord::Base && !parent.abstract_class?
  996 + contained = parent.table_name
  997 + contained = contained.singularize if parent.pluralize_table_names
  998 + contained << '_'
  999 + end
  1000 + "#{full_table_name_prefix}#{contained}#{undecorated_table_name(name)}#{table_name_suffix}"
  1001 + else
  1002 + # STI subclasses always use their superclass' table.
  1003 + base.table_name
  1004 + end
  1005 + end
  1006 +
1004 1007 # Enables dynamic finders like <tt>find_by_user_name(user_name)</tt> and <tt>find_by_user_name_and_password(user_name, password)</tt>
1005 1008 # that are turned into <tt>where(:user_name => user_name).first</tt> and <tt>where(:user_name => user_name, :password => :password).first</tt>
1006 1009 # respectively. Also works for <tt>all</tt> by using <tt>find_all_by_amount(50)</tt> that is turned into <tt>where(:amount => 50).all</tt>.

0 comments on commit 5cd3c2a

Please sign in to comment.
Something went wrong with that request. Please try again.