activerecord 3.0.20 → 3.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activerecord might be problematic. Click here for more details.

Files changed (122) hide show
  1. data/CHANGELOG +220 -91
  2. data/README.rdoc +3 -3
  3. data/examples/performance.rb +88 -109
  4. data/lib/active_record.rb +6 -2
  5. data/lib/active_record/aggregations.rb +22 -45
  6. data/lib/active_record/associations.rb +264 -991
  7. data/lib/active_record/associations/alias_tracker.rb +85 -0
  8. data/lib/active_record/associations/association.rb +231 -0
  9. data/lib/active_record/associations/association_scope.rb +120 -0
  10. data/lib/active_record/associations/belongs_to_association.rb +40 -60
  11. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +15 -63
  12. data/lib/active_record/associations/builder/association.rb +53 -0
  13. data/lib/active_record/associations/builder/belongs_to.rb +85 -0
  14. data/lib/active_record/associations/builder/collection_association.rb +75 -0
  15. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +63 -0
  16. data/lib/active_record/associations/builder/has_many.rb +65 -0
  17. data/lib/active_record/associations/builder/has_one.rb +63 -0
  18. data/lib/active_record/associations/builder/singular_association.rb +32 -0
  19. data/lib/active_record/associations/collection_association.rb +524 -0
  20. data/lib/active_record/associations/collection_proxy.rb +125 -0
  21. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +27 -118
  22. data/lib/active_record/associations/has_many_association.rb +50 -79
  23. data/lib/active_record/associations/has_many_through_association.rb +98 -67
  24. data/lib/active_record/associations/has_one_association.rb +45 -115
  25. data/lib/active_record/associations/has_one_through_association.rb +21 -25
  26. data/lib/active_record/associations/join_dependency.rb +215 -0
  27. data/lib/active_record/associations/join_dependency/join_association.rb +150 -0
  28. data/lib/active_record/associations/join_dependency/join_base.rb +24 -0
  29. data/lib/active_record/associations/join_dependency/join_part.rb +78 -0
  30. data/lib/active_record/associations/join_helper.rb +56 -0
  31. data/lib/active_record/associations/preloader.rb +177 -0
  32. data/lib/active_record/associations/preloader/association.rb +126 -0
  33. data/lib/active_record/associations/preloader/belongs_to.rb +17 -0
  34. data/lib/active_record/associations/preloader/collection_association.rb +24 -0
  35. data/lib/active_record/associations/preloader/has_and_belongs_to_many.rb +60 -0
  36. data/lib/active_record/associations/preloader/has_many.rb +17 -0
  37. data/lib/active_record/associations/preloader/has_many_through.rb +15 -0
  38. data/lib/active_record/associations/preloader/has_one.rb +23 -0
  39. data/lib/active_record/associations/preloader/has_one_through.rb +9 -0
  40. data/lib/active_record/associations/preloader/singular_association.rb +21 -0
  41. data/lib/active_record/associations/preloader/through_association.rb +67 -0
  42. data/lib/active_record/associations/singular_association.rb +55 -0
  43. data/lib/active_record/associations/through_association.rb +80 -0
  44. data/lib/active_record/attribute_methods.rb +19 -5
  45. data/lib/active_record/attribute_methods/before_type_cast.rb +9 -8
  46. data/lib/active_record/attribute_methods/dirty.rb +8 -2
  47. data/lib/active_record/attribute_methods/primary_key.rb +33 -13
  48. data/lib/active_record/attribute_methods/read.rb +17 -17
  49. data/lib/active_record/attribute_methods/time_zone_conversion.rb +7 -4
  50. data/lib/active_record/attribute_methods/write.rb +2 -1
  51. data/lib/active_record/autosave_association.rb +66 -45
  52. data/lib/active_record/base.rb +445 -273
  53. data/lib/active_record/callbacks.rb +24 -33
  54. data/lib/active_record/coders/yaml_column.rb +41 -0
  55. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +106 -13
  56. data/lib/active_record/connection_adapters/abstract/connection_specification.rb +16 -2
  57. data/lib/active_record/connection_adapters/abstract/database_limits.rb +12 -11
  58. data/lib/active_record/connection_adapters/abstract/database_statements.rb +83 -12
  59. data/lib/active_record/connection_adapters/abstract/query_cache.rb +16 -16
  60. data/lib/active_record/connection_adapters/abstract/quoting.rb +61 -22
  61. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +16 -273
  62. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +80 -42
  63. data/lib/active_record/connection_adapters/abstract_adapter.rb +44 -25
  64. data/lib/active_record/connection_adapters/column.rb +268 -0
  65. data/lib/active_record/connection_adapters/mysql2_adapter.rb +686 -0
  66. data/lib/active_record/connection_adapters/mysql_adapter.rb +331 -88
  67. data/lib/active_record/connection_adapters/postgresql_adapter.rb +295 -267
  68. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +3 -7
  69. data/lib/active_record/connection_adapters/sqlite_adapter.rb +108 -26
  70. data/lib/active_record/counter_cache.rb +7 -4
  71. data/lib/active_record/fixtures.rb +174 -192
  72. data/lib/active_record/identity_map.rb +131 -0
  73. data/lib/active_record/locking/optimistic.rb +20 -14
  74. data/lib/active_record/locking/pessimistic.rb +4 -4
  75. data/lib/active_record/log_subscriber.rb +24 -4
  76. data/lib/active_record/migration.rb +265 -144
  77. data/lib/active_record/migration/command_recorder.rb +103 -0
  78. data/lib/active_record/named_scope.rb +68 -25
  79. data/lib/active_record/nested_attributes.rb +58 -15
  80. data/lib/active_record/observer.rb +3 -7
  81. data/lib/active_record/persistence.rb +58 -38
  82. data/lib/active_record/query_cache.rb +25 -3
  83. data/lib/active_record/railtie.rb +21 -12
  84. data/lib/active_record/railties/console_sandbox.rb +6 -0
  85. data/lib/active_record/railties/databases.rake +147 -116
  86. data/lib/active_record/railties/jdbcmysql_error.rb +1 -1
  87. data/lib/active_record/reflection.rb +176 -44
  88. data/lib/active_record/relation.rb +125 -49
  89. data/lib/active_record/relation/batches.rb +7 -5
  90. data/lib/active_record/relation/calculations.rb +50 -18
  91. data/lib/active_record/relation/finder_methods.rb +47 -26
  92. data/lib/active_record/relation/predicate_builder.rb +24 -21
  93. data/lib/active_record/relation/query_methods.rb +117 -101
  94. data/lib/active_record/relation/spawn_methods.rb +27 -20
  95. data/lib/active_record/result.rb +34 -0
  96. data/lib/active_record/schema.rb +5 -6
  97. data/lib/active_record/schema_dumper.rb +11 -13
  98. data/lib/active_record/serialization.rb +2 -2
  99. data/lib/active_record/serializers/xml_serializer.rb +10 -10
  100. data/lib/active_record/session_store.rb +8 -2
  101. data/lib/active_record/test_case.rb +9 -20
  102. data/lib/active_record/timestamp.rb +21 -9
  103. data/lib/active_record/transactions.rb +16 -15
  104. data/lib/active_record/validations.rb +21 -22
  105. data/lib/active_record/validations/associated.rb +3 -1
  106. data/lib/active_record/validations/uniqueness.rb +48 -58
  107. data/lib/active_record/version.rb +3 -3
  108. data/lib/rails/generators/active_record.rb +6 -0
  109. data/lib/rails/generators/active_record/migration/templates/migration.rb +10 -2
  110. data/lib/rails/generators/active_record/model/model_generator.rb +2 -1
  111. data/lib/rails/generators/active_record/model/templates/migration.rb +6 -5
  112. data/lib/rails/generators/active_record/model/templates/model.rb +2 -0
  113. data/lib/rails/generators/active_record/model/templates/module.rb +2 -0
  114. data/lib/rails/generators/active_record/observer/templates/observer.rb +2 -0
  115. data/lib/rails/generators/active_record/session_migration/session_migration_generator.rb +2 -1
  116. data/lib/rails/generators/active_record/session_migration/templates/migration.rb +2 -2
  117. metadata +106 -77
  118. checksums.yaml +0 -7
  119. data/lib/active_record/association_preload.rb +0 -431
  120. data/lib/active_record/associations/association_collection.rb +0 -572
  121. data/lib/active_record/associations/association_proxy.rb +0 -304
  122. data/lib/active_record/associations/through_association_scope.rb +0 -160
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
- # = Active Record Validations
2
+ # = Active Record RecordInvalid
3
3
  #
4
4
  # Raised by <tt>save!</tt> and <tt>create!</tt> when the record is invalid. Use the
5
5
  # +record+ method to retrieve the record which did not validate.
@@ -18,12 +18,19 @@ module ActiveRecord
18
18
  end
19
19
  end
20
20
 
21
+ # = Active Record Validations
22
+ #
23
+ # Active Record includes the majority of its validations from <tt>ActiveModel::Validations</tt>
24
+ # all of which accept the <tt>:on</tt> argument to define the context where the
25
+ # validations are active. Active Record will always supply either the context of
26
+ # <tt>:create</tt> or <tt>:update</tt> dependent on whether the model is a
27
+ # <tt>new_record?</tt>.
21
28
  module Validations
22
29
  extend ActiveSupport::Concern
23
30
  include ActiveModel::Validations
24
31
 
25
32
  module ClassMethods
26
- # Creates an object just like Base.create but calls save! instead of save
33
+ # Creates an object just like Base.create but calls <tt>save!</tt> instead of +save+
27
34
  # so an exception is raised if the record is invalid.
28
35
  def create!(attributes = nil, &block)
29
36
  if attributes.is_a?(Array)
@@ -37,45 +44,37 @@ module ActiveRecord
37
44
  end
38
45
  end
39
46
 
40
- # The validation process on save can be skipped by passing false. The regular Base#save method is
47
+ # The validation process on save can be skipped by passing <tt>:validate => false</tt>. The regular Base#save method is
41
48
  # replaced with this when the validations module is mixed in, which it is by default.
42
49
  def save(options={})
43
50
  perform_validations(options) ? super : false
44
51
  end
45
52
 
46
- # Attempts to save the record just like Base#save but will raise a RecordInvalid exception instead of returning false
53
+ # Attempts to save the record just like Base#save but will raise a +RecordInvalid+ exception instead of returning false
47
54
  # if the record is not valid.
48
55
  def save!(options={})
49
56
  perform_validations(options) ? super : raise(RecordInvalid.new(self))
50
57
  end
51
58
 
52
- # Runs all the specified validations and returns true if no errors were added otherwise false.
59
+ # Runs all the validations within the specified context. Returns true if no errors are found,
60
+ # false otherwise.
61
+ #
62
+ # If the argument is false (default is +nil+), the context is set to <tt>:create</tt> if
63
+ # <tt>new_record?</tt> is true, and to <tt>:update</tt> if it is not.
64
+ #
65
+ # Validations with no <tt>:on</tt> option will run no matter the context. Validations with
66
+ # some <tt>:on</tt> option will only run in the specified context.
53
67
  def valid?(context = nil)
54
68
  context ||= (new_record? ? :create : :update)
55
69
  output = super(context)
56
-
57
- deprecated_callback_method(:validate)
58
- deprecated_callback_method(:"validate_on_#{context}")
59
-
60
70
  errors.empty? && output
61
71
  end
62
72
 
63
73
  protected
64
74
 
65
75
  def perform_validations(options={})
66
- perform_validation = case options
67
- when Hash
68
- options[:validate] != false
69
- else
70
- ActiveSupport::Deprecation.warn "save(#{options}) is deprecated, please give save(:validate => #{options}) instead", caller
71
- options
72
- end
73
-
74
- if perform_validation
75
- valid?(options.is_a?(Hash) ? options[:context] : nil)
76
- else
77
- true
78
- end
76
+ perform_validation = options[:validate] != false
77
+ perform_validation ? valid?(options[:context]) : true
79
78
  end
80
79
  end
81
80
  end
@@ -33,7 +33,9 @@ module ActiveRecord
33
33
  #
34
34
  # Configuration options:
35
35
  # * <tt>:message</tt> - A custom error message (default is: "is invalid")
36
- # * <tt>:on</tt> - Specifies when this validation is active (default is <tt>:save</tt>, other options <tt>:create</tt>, <tt>:update</tt>).
36
+ # * <tt>:on</tt> - Specifies when this validation is active. Runs in all
37
+ # validation contexts by default (+nil+), other options are <tt>:create</tt>
38
+ # and <tt>:update</tt>.
37
39
  # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
38
40
  # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
39
41
  # method, proc or string should return or evaluate to a true or false value.
@@ -14,29 +14,23 @@ module ActiveRecord
14
14
 
15
15
  def validate_each(record, attribute, value)
16
16
  finder_class = find_finder_class_for(record)
17
- table = finder_class.unscoped
17
+ table = finder_class.arel_table
18
18
 
19
- table_name = record.class.quoted_table_name
19
+ coder = record.class.serialized_attributes[attribute.to_s]
20
20
 
21
- if value && record.class.serialized_attributes.key?(attribute.to_s)
22
- value = YAML.dump value
21
+ if value && coder
22
+ value = coder.dump value
23
23
  end
24
24
 
25
- sql, params = mount_sql_and_params(finder_class, table_name, attribute, value)
26
-
27
- relation = table.where(sql, *params)
25
+ relation = build_relation(finder_class, table, attribute, value)
26
+ relation = relation.and(table[finder_class.primary_key.to_sym].not_eq(record.send(:id))) if record.persisted?
28
27
 
29
28
  Array.wrap(options[:scope]).each do |scope_item|
30
29
  scope_value = record.send(scope_item)
31
- relation = relation.where(scope_item => scope_value)
32
- end
33
-
34
- unless record.new_record?
35
- # TODO : This should be in Arel
36
- relation = relation.where("#{record.class.quoted_table_name}.#{record.class.primary_key} <> ?", record.send(:id))
30
+ relation = relation.and(table[scope_item].eq(scope_value))
37
31
  end
38
32
 
39
- if relation.exists?
33
+ if finder_class.unscoped.where(relation).exists?
40
34
  record.errors.add(attribute, :taken, options.except(:case_sensitive, :scope).merge(:value => value))
41
35
  end
42
36
  end
@@ -58,27 +52,19 @@ module ActiveRecord
58
52
  class_hierarchy.detect { |klass| !klass.abstract_class? }
59
53
  end
60
54
 
61
- def mount_sql_and_params(klass, table_name, attribute, value) #:nodoc:
55
+ def build_relation(klass, table, attribute, value) #:nodoc:
62
56
  column = klass.columns_hash[attribute.to_s]
57
+ value = column.limit ? value.to_s.mb_chars[0, column.limit] : value.to_s if column.text?
63
58
 
64
- operator = if value.nil?
65
- "IS ?"
66
- elsif column.text?
67
- value = column.limit ? value.to_s.mb_chars[0, column.limit] : value.to_s
68
- "#{klass.connection.case_sensitive_equality_operator} ?"
69
- else
70
- "= ?"
71
- end
72
-
73
- sql_attribute = "#{table_name}.#{klass.connection.quote_column_name(attribute)}"
74
-
75
- if value.nil? || (options[:case_sensitive] || !column.text?)
76
- sql = "#{sql_attribute} #{operator}"
59
+ if !options[:case_sensitive] && value && column.text?
60
+ # will use SQL LOWER function before comparison
61
+ relation = table[attribute].lower.eq(table.lower(value))
77
62
  else
78
- sql = "LOWER(#{sql_attribute}) = LOWER(?)"
63
+ value = klass.connection.case_sensitive_modifier(value)
64
+ relation = table[attribute].eq(value)
79
65
  end
80
66
 
81
- [sql, [value]]
67
+ relation
82
68
  end
83
69
  end
84
70
 
@@ -88,11 +74,16 @@ module ActiveRecord
88
74
  # can be named "davidhh".
89
75
  #
90
76
  # class Person < ActiveRecord::Base
91
- # validates_uniqueness_of :user_name, :scope => :account_id
77
+ # validates_uniqueness_of :user_name
92
78
  # end
93
79
  #
94
- # It can also validate whether the value of the specified attributes are unique based on multiple
95
- # scope parameters. For example, making sure that a teacher can only be on the schedule once
80
+ # It can also validate whether the value of the specified attributes are unique based on a scope parameter:
81
+ #
82
+ # class Person < ActiveRecord::Base
83
+ # validates_uniqueness_of :user_name, :scope => :account_id
84
+ # end
85
+ #
86
+ # Or even multiple scope parameters. For example, making sure that a teacher can only be on the schedule once
96
87
  # per semester for a particular class.
97
88
  #
98
89
  # class TeacherSchedule < ActiveRecord::Base
@@ -154,33 +145,32 @@ module ActiveRecord
154
145
  # | # title!
155
146
  #
156
147
  # This could even happen if you use transactions with the 'serializable'
157
- # isolation level. There are several ways to get around this problem:
158
- #
159
- # - By locking the database table before validating, and unlocking it after
160
- # saving. However, table locking is very expensive, and thus not
161
- # recommended.
162
- # - By locking a lock file before validating, and unlocking it after saving.
163
- # This does not work if you've scaled your Rails application across
164
- # multiple web servers (because they cannot share lock files, or cannot
165
- # do that efficiently), and thus not recommended.
166
- # - Creating a unique index on the field, by using
167
- # ActiveRecord::ConnectionAdapters::SchemaStatements#add_index. In the
168
- # rare case that a race condition occurs, the database will guarantee
169
- # the field's uniqueness.
148
+ # isolation level. The best way to work around this problem is to add a unique
149
+ # index to the database table using
150
+ # ActiveRecord::ConnectionAdapters::SchemaStatements#add_index. In the
151
+ # rare case that a race condition occurs, the database will guarantee
152
+ # the field's uniqueness.
170
153
  #
171
- # When the database catches such a duplicate insertion,
172
- # ActiveRecord::Base#save will raise an ActiveRecord::StatementInvalid
173
- # exception. You can either choose to let this error propagate (which
174
- # will result in the default Rails exception page being shown), or you
175
- # can catch it and restart the transaction (e.g. by telling the user
176
- # that the title already exists, and asking him to re-enter the title).
177
- # This technique is also known as optimistic concurrency control:
178
- # http://en.wikipedia.org/wiki/Optimistic_concurrency_control
154
+ # When the database catches such a duplicate insertion,
155
+ # ActiveRecord::Base#save will raise an ActiveRecord::StatementInvalid
156
+ # exception. You can either choose to let this error propagate (which
157
+ # will result in the default Rails exception page being shown), or you
158
+ # can catch it and restart the transaction (e.g. by telling the user
159
+ # that the title already exists, and asking him to re-enter the title).
160
+ # This technique is also known as optimistic concurrency control:
161
+ # http://en.wikipedia.org/wiki/Optimistic_concurrency_control
179
162
  #
180
- # Active Record currently provides no way to distinguish unique
181
- # index constraint errors from other types of database errors, so you
182
- # will have to parse the (database-specific) exception message to detect
183
- # such a case.
163
+ # The bundled ActiveRecord::ConnectionAdapters distinguish unique index
164
+ # constraint errors from other types of database errors by throwing an
165
+ # ActiveRecord::RecordNotUnique exception.
166
+ # For other adapters you will have to parse the (database-specific) exception
167
+ # message to detect such a case.
168
+ # The following bundled adapters throw the ActiveRecord::RecordNotUnique exception:
169
+ # * ActiveRecord::ConnectionAdapters::MysqlAdapter
170
+ # * ActiveRecord::ConnectionAdapters::Mysql2Adapter
171
+ # * ActiveRecord::ConnectionAdapters::SQLiteAdapter
172
+ # * ActiveRecord::ConnectionAdapters::SQLite3Adapter
173
+ # * ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
184
174
  #
185
175
  def validates_uniqueness_of(*attr_names)
186
176
  validates_with UniquenessValidator, _merge_attributes(attr_names)
@@ -1,9 +1,9 @@
1
1
  module ActiveRecord
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 3
4
- MINOR = 0
5
- TINY = 20
6
- PRE = nil
4
+ MINOR = 1
5
+ TINY = 0
6
+ PRE = "beta1"
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
9
9
  end
@@ -14,6 +14,12 @@ module ActiveRecord
14
14
  def self.base_root
15
15
  File.dirname(__FILE__)
16
16
  end
17
+
18
+ # Implement the required interface for Rails::Generators::Migration.
19
+ def self.next_migration_number(dirname) #:nodoc:
20
+ next_migration_number = current_migration_number(dirname) + 1
21
+ ActiveRecord::Migration.next_migration_number(next_migration_number)
22
+ end
17
23
  end
18
24
  end
19
25
  end
@@ -1,5 +1,12 @@
1
1
  class <%= migration_class_name %> < ActiveRecord::Migration
2
- def self.up
2
+ <%- if migration_action == 'add' -%>
3
+ def change
4
+ <% attributes.each do |attribute| -%>
5
+ add_column :<%= table_name %>, :<%= attribute.name %>, :<%= attribute.type %>
6
+ <%- end -%>
7
+ end
8
+ <%- else -%>
9
+ def up
3
10
  <% attributes.each do |attribute| -%>
4
11
  <%- if migration_action -%>
5
12
  <%= migration_action %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'add' %>, :<%= attribute.type %><% end %>
@@ -7,11 +14,12 @@ class <%= migration_class_name %> < ActiveRecord::Migration
7
14
  <%- end -%>
8
15
  end
9
16
 
10
- def self.down
17
+ def down
11
18
  <% attributes.reverse.each do |attribute| -%>
12
19
  <%- if migration_action -%>
13
20
  <%= migration_action == 'add' ? 'remove' : 'add' %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'remove' %>, :<%= attribute.type %><% end %>
14
21
  <%- end -%>
15
22
  <%- end -%>
16
23
  end
24
+ <%- end -%>
17
25
  end
@@ -10,6 +10,7 @@ module ActiveRecord
10
10
  class_option :migration, :type => :boolean
11
11
  class_option :timestamps, :type => :boolean
12
12
  class_option :parent, :type => :string, :desc => "The parent class for the generated model"
13
+ class_option :indexes, :type => :boolean, :default => true, :desc => "Add indexes for references and belongs_to columns"
13
14
 
14
15
  def create_migration_file
15
16
  return unless options[:migration] && options[:parent].nil?
@@ -21,7 +22,7 @@ module ActiveRecord
21
22
  end
22
23
 
23
24
  def create_module_file
24
- return if class_path.empty?
25
+ return if regular_class_path.empty?
25
26
  template 'module.rb', File.join('app/models', "#{class_path.join('/')}.rb") if behavior == :invoke
26
27
  end
27
28
 
@@ -1,5 +1,5 @@
1
1
  class <%= migration_class_name %> < ActiveRecord::Migration
2
- def self.up
2
+ def change
3
3
  create_table :<%= table_name %> do |t|
4
4
  <% for attribute in attributes -%>
5
5
  t.<%= attribute.type %> :<%= attribute.name %>
@@ -8,9 +8,10 @@ class <%= migration_class_name %> < ActiveRecord::Migration
8
8
  t.timestamps
9
9
  <% end -%>
10
10
  end
11
- end
12
-
13
- def self.down
14
- drop_table :<%= table_name %>
11
+ <% if options[:indexes] -%>
12
+ <% attributes.select {|attr| attr.reference? }.each do |attribute| -%>
13
+ add_index :<%= table_name %>, :<%= attribute.name %>_id
14
+ <% end -%>
15
+ <% end -%>
15
16
  end
16
17
  end
@@ -1,5 +1,7 @@
1
+ <% module_namespacing do -%>
1
2
  class <%= class_name %> < <%= parent_class_name.classify %>
2
3
  <% attributes.select {|attr| attr.reference? }.each do |attribute| -%>
3
4
  belongs_to :<%= attribute.name %>
4
5
  <% end -%>
5
6
  end
7
+ <% end -%>
@@ -1,5 +1,7 @@
1
+ <% module_namespacing do -%>
1
2
  module <%= class_path.map(&:camelize).join('::') %>
2
3
  def self.table_name_prefix
3
4
  '<%= class_path.join('_') %>_'
4
5
  end
5
6
  end
7
+ <% end -%>
@@ -1,2 +1,4 @@
1
+ <% module_namespacing do -%>
1
2
  class <%= class_name %>Observer < ActiveRecord::Observer
2
3
  end
4
+ <% end -%>
@@ -1,4 +1,5 @@
1
1
  require 'rails/generators/active_record'
2
+ require 'active_support/core_ext/object/inclusion'
2
3
 
3
4
  module ActiveRecord
4
5
  module Generators
@@ -13,7 +14,7 @@ module ActiveRecord
13
14
 
14
15
  def session_table_name
15
16
  current_table_name = ActiveRecord::SessionStore::Session.table_name
16
- if ["sessions", "session"].include?(current_table_name)
17
+ if current_table_name.in?(["sessions", "session"])
17
18
  current_table_name = (ActiveRecord::Base.pluralize_table_names ? 'session'.pluralize : 'session')
18
19
  end
19
20
  current_table_name
@@ -1,5 +1,5 @@
1
1
  class <%= migration_class_name %> < ActiveRecord::Migration
2
- def self.up
2
+ def up
3
3
  create_table :<%= session_table_name %> do |t|
4
4
  t.string :session_id, :null => false
5
5
  t.text :data
@@ -10,7 +10,7 @@ class <%= migration_class_name %> < ActiveRecord::Migration
10
10
  add_index :<%= session_table_name %>, :updated_at
11
11
  end
12
12
 
13
- def self.down
13
+ def down
14
14
  drop_table :<%= session_table_name %>
15
15
  end
16
16
  end
metadata CHANGED
@@ -1,97 +1,114 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: activerecord
3
- version: !ruby/object:Gem::Version
4
- version: 3.0.20
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: 6
5
+ version: 3.1.0.beta1
5
6
  platform: ruby
6
- authors:
7
+ authors:
7
8
  - David Heinemeier Hansson
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-01-28 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
12
+
13
+ date: 2011-05-04 00:00:00 -05:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
14
17
  name: activesupport
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '='
18
- - !ruby/object:Gem::Version
19
- version: 3.0.20
20
- type: :runtime
21
18
  prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '='
25
- - !ruby/object:Gem::Version
26
- version: 3.0.20
27
- - !ruby/object:Gem::Dependency
28
- name: activemodel
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - '='
32
- - !ruby/object:Gem::Version
33
- version: 3.0.20
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - "="
23
+ - !ruby/object:Gem::Version
24
+ version: 3.1.0.beta1
34
25
  type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: activemodel
35
29
  prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - '='
39
- - !ruby/object:Gem::Version
40
- version: 3.0.20
41
- - !ruby/object:Gem::Dependency
42
- name: arel
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: 2.0.10
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - "="
34
+ - !ruby/object:Gem::Version
35
+ version: 3.1.0.beta1
48
36
  type: :runtime
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: arel
49
40
  prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: 2.0.10
55
- - !ruby/object:Gem::Dependency
56
- name: tzinfo
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: 0.3.23
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 2.1.0
62
47
  type: :runtime
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: tzinfo
63
51
  prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: 0.3.23
69
- description: Databases on Rails. Build a persistent domain model by mapping database
70
- tables to Ruby classes. Strong conventions for associations, validations, aggregations,
71
- migrations, and testing come baked-in.
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ version: 0.3.27
58
+ type: :runtime
59
+ version_requirements: *id004
60
+ description: Databases on Rails. Build a persistent domain model by mapping database tables to Ruby classes. Strong conventions for associations, validations, aggregations, migrations, and testing come baked-in.
72
61
  email: david@loudthinking.com
73
62
  executables: []
63
+
74
64
  extensions: []
75
- extra_rdoc_files:
65
+
66
+ extra_rdoc_files:
76
67
  - README.rdoc
77
- files:
68
+ files:
78
69
  - CHANGELOG
79
70
  - README.rdoc
80
71
  - examples/associations.png
81
72
  - examples/performance.rb
82
73
  - examples/simple.rb
83
74
  - lib/active_record/aggregations.rb
84
- - lib/active_record/association_preload.rb
85
- - lib/active_record/associations/association_collection.rb
86
- - lib/active_record/associations/association_proxy.rb
75
+ - lib/active_record/associations/alias_tracker.rb
76
+ - lib/active_record/associations/association.rb
77
+ - lib/active_record/associations/association_scope.rb
87
78
  - lib/active_record/associations/belongs_to_association.rb
88
79
  - lib/active_record/associations/belongs_to_polymorphic_association.rb
80
+ - lib/active_record/associations/builder/association.rb
81
+ - lib/active_record/associations/builder/belongs_to.rb
82
+ - lib/active_record/associations/builder/collection_association.rb
83
+ - lib/active_record/associations/builder/has_and_belongs_to_many.rb
84
+ - lib/active_record/associations/builder/has_many.rb
85
+ - lib/active_record/associations/builder/has_one.rb
86
+ - lib/active_record/associations/builder/singular_association.rb
87
+ - lib/active_record/associations/collection_association.rb
88
+ - lib/active_record/associations/collection_proxy.rb
89
89
  - lib/active_record/associations/has_and_belongs_to_many_association.rb
90
90
  - lib/active_record/associations/has_many_association.rb
91
91
  - lib/active_record/associations/has_many_through_association.rb
92
92
  - lib/active_record/associations/has_one_association.rb
93
93
  - lib/active_record/associations/has_one_through_association.rb
94
- - lib/active_record/associations/through_association_scope.rb
94
+ - lib/active_record/associations/join_dependency/join_association.rb
95
+ - lib/active_record/associations/join_dependency/join_base.rb
96
+ - lib/active_record/associations/join_dependency/join_part.rb
97
+ - lib/active_record/associations/join_dependency.rb
98
+ - lib/active_record/associations/join_helper.rb
99
+ - lib/active_record/associations/preloader/association.rb
100
+ - lib/active_record/associations/preloader/belongs_to.rb
101
+ - lib/active_record/associations/preloader/collection_association.rb
102
+ - lib/active_record/associations/preloader/has_and_belongs_to_many.rb
103
+ - lib/active_record/associations/preloader/has_many.rb
104
+ - lib/active_record/associations/preloader/has_many_through.rb
105
+ - lib/active_record/associations/preloader/has_one.rb
106
+ - lib/active_record/associations/preloader/has_one_through.rb
107
+ - lib/active_record/associations/preloader/singular_association.rb
108
+ - lib/active_record/associations/preloader/through_association.rb
109
+ - lib/active_record/associations/preloader.rb
110
+ - lib/active_record/associations/singular_association.rb
111
+ - lib/active_record/associations/through_association.rb
95
112
  - lib/active_record/associations.rb
96
113
  - lib/active_record/attribute_methods/before_type_cast.rb
97
114
  - lib/active_record/attribute_methods/dirty.rb
@@ -104,6 +121,7 @@ files:
104
121
  - lib/active_record/autosave_association.rb
105
122
  - lib/active_record/base.rb
106
123
  - lib/active_record/callbacks.rb
124
+ - lib/active_record/coders/yaml_column.rb
107
125
  - lib/active_record/connection_adapters/abstract/connection_pool.rb
108
126
  - lib/active_record/connection_adapters/abstract/connection_specification.rb
109
127
  - lib/active_record/connection_adapters/abstract/database_limits.rb
@@ -113,6 +131,8 @@ files:
113
131
  - lib/active_record/connection_adapters/abstract/schema_definitions.rb
114
132
  - lib/active_record/connection_adapters/abstract/schema_statements.rb
115
133
  - lib/active_record/connection_adapters/abstract_adapter.rb
134
+ - lib/active_record/connection_adapters/column.rb
135
+ - lib/active_record/connection_adapters/mysql2_adapter.rb
116
136
  - lib/active_record/connection_adapters/mysql_adapter.rb
117
137
  - lib/active_record/connection_adapters/postgresql_adapter.rb
118
138
  - lib/active_record/connection_adapters/sqlite3_adapter.rb
@@ -122,10 +142,12 @@ files:
122
142
  - lib/active_record/dynamic_scope_match.rb
123
143
  - lib/active_record/errors.rb
124
144
  - lib/active_record/fixtures.rb
145
+ - lib/active_record/identity_map.rb
125
146
  - lib/active_record/locale/en.yml
126
147
  - lib/active_record/locking/optimistic.rb
127
148
  - lib/active_record/locking/pessimistic.rb
128
149
  - lib/active_record/log_subscriber.rb
150
+ - lib/active_record/migration/command_recorder.rb
129
151
  - lib/active_record/migration.rb
130
152
  - lib/active_record/named_scope.rb
131
153
  - lib/active_record/nested_attributes.rb
@@ -133,6 +155,7 @@ files:
133
155
  - lib/active_record/persistence.rb
134
156
  - lib/active_record/query_cache.rb
135
157
  - lib/active_record/railtie.rb
158
+ - lib/active_record/railties/console_sandbox.rb
136
159
  - lib/active_record/railties/controller_runtime.rb
137
160
  - lib/active_record/railties/databases.rake
138
161
  - lib/active_record/railties/jdbcmysql_error.rb
@@ -144,6 +167,7 @@ files:
144
167
  - lib/active_record/relation/query_methods.rb
145
168
  - lib/active_record/relation/spawn_methods.rb
146
169
  - lib/active_record/relation.rb
170
+ - lib/active_record/result.rb
147
171
  - lib/active_record/schema.rb
148
172
  - lib/active_record/schema_dumper.rb
149
173
  - lib/active_record/serialization.rb
@@ -169,29 +193,34 @@ files:
169
193
  - lib/rails/generators/active_record/session_migration/session_migration_generator.rb
170
194
  - lib/rails/generators/active_record/session_migration/templates/migration.rb
171
195
  - lib/rails/generators/active_record.rb
196
+ has_rdoc: true
172
197
  homepage: http://www.rubyonrails.org
173
198
  licenses: []
174
- metadata: {}
199
+
175
200
  post_install_message:
176
- rdoc_options:
177
- - "--main"
201
+ rdoc_options:
202
+ - --main
178
203
  - README.rdoc
179
- require_paths:
204
+ require_paths:
180
205
  - lib
181
- required_ruby_version: !ruby/object:Gem::Requirement
182
- requirements:
206
+ required_ruby_version: !ruby/object:Gem::Requirement
207
+ none: false
208
+ requirements:
183
209
  - - ">="
184
- - !ruby/object:Gem::Version
210
+ - !ruby/object:Gem::Version
185
211
  version: 1.8.7
186
- required_rubygems_version: !ruby/object:Gem::Requirement
187
- requirements:
188
- - - ">="
189
- - !ruby/object:Gem::Version
190
- version: '0'
212
+ required_rubygems_version: !ruby/object:Gem::Requirement
213
+ none: false
214
+ requirements:
215
+ - - ">"
216
+ - !ruby/object:Gem::Version
217
+ version: 1.3.1
191
218
  requirements: []
219
+
192
220
  rubyforge_project: activerecord
193
- rubygems_version: 2.0.0.preview3.1
221
+ rubygems_version: 1.6.2
194
222
  signing_key:
195
- specification_version: 4
223
+ specification_version: 3
196
224
  summary: Object-relational mapper framework (part of Rails).
197
225
  test_files: []
226
+