Commit Graph

13165 Commits

Author SHA1 Message Date
Sean Griffin 7eed50c720 Rely on the injectable type caster for `arel_table`
This API will require much less consuming code to change to accomodate
the removal of automatic type casting from Arel. As long as the
predicates are constructed using the `arel_table` off of an AR subclass,
there will be no changes that need to happen.
2014-12-29 10:57:15 -07:00
Rafael Mendonça França 266ff70001 Merge pull request #18097 from k0kubun/readonly-eager_load
`eager_load` preserves readonly flag for associations
2014-12-29 14:18:54 -03:00
Rafael Mendonça França 0906e8322b Add nodoc to touch at no_touching.rb
It is already docummented at persistence.rb.

[ci skip]
2014-12-29 14:14:46 -03:00
Takashi Kokubun 068160b444 `eager_load` preserves readonly flag for associations 2014-12-30 01:07:33 +09:00
Ryuta Kamizono 3628025c0d Improve a dump of the primary key support.
If it is not a default primary key, correctly dump the type and options.
2014-12-29 09:19:21 +09:00
Robin Dupret 73fe108d70 Minor documentation edits [ci skip] 2014-12-28 22:55:09 +01:00
Guillermo Iguaran edaab4dbe8 Merge pull request #18209 from claudiob/bump-to-2-2
Require Ruby 2.2 for Rails 5.0
2014-12-28 16:39:39 -05:00
Yves Senn ed7196645c docs, cleanup Active Record CHANGELOG. [ci skip] 2014-12-28 22:25:42 +01:00
Ryuta Kamizono 5f1a9bbec0 Fix warning: `*' interpreted as argument prefix 2014-12-28 16:05:53 +09:00
Dan Olson e780e2fda3 Provide :touch option to save() to accommodate saving without updating timestamps. [#18202] 2014-12-27 22:22:37 -06:00
Sean Griffin 307ec3db0f Provide a better error message for unsupported classes in `serialize`
We only support classes which provide a no-args constructor to use as a
default value. We can provide a more helpful error message if we catch
this when `serialize` is called, rather than letting it error when you
try to assign the attribute.

Fixes #18224
2014-12-27 19:49:09 -07:00
Ryuta Kamizono a327a9dc58 Add bigint primary key support for MySQL.
Example:

    create_table :foos, id: :bigint do |t|
    end
2014-12-28 05:35:03 +09:00
Ryuta Kamizono 3cbfba6881 Support for any type primary key. 2014-12-28 05:35:03 +09:00
Yves Senn baaad864e8 add autoload for `ForeignKeyDefinition`.
/cc @sgrif
2014-12-27 19:43:42 +01:00
Yves Senn e2d8553005 reduce duplication in `ConnectionAdapters::Table` docs. [ci skip]
Most of the documentation very closely mirrors the matching
docs from `SchemaStatements`. I reduced duplicated copy and
added links to the underlying methods for the user to follow.
2014-12-27 19:09:43 +01:00
Ryuta Kamizono 11054049ca Refactor `PostgreSQL::TableDefinition#primary_key`
Because call the `column` method and set the `options[:primary_key]` is
handled at `super`, here need only treat the `options[:default]`.
2014-12-27 23:13:19 +09:00
Sean Griffin de0cfd27a5 Inform Arel we don't need additional type casting in tests
Part of the larger refactoring to remove type casting from Arel. We can
inform it that we already have the right type by wrapping the value in
an `Arel::Nodes::Quoted`. This commit can be reverted when we have
removed type casting from Arel in Rail 5.1
2014-12-26 17:50:20 -07:00
Sean Griffin 108df8cc90 Inform Arel we don't need additional type casting in batches
Part of the larger refactoring to remove type casting from Arel. We can
inform it that we already have the right type by wrapping the value in
an `Arel::Nodes::Quoted`. This commit can be reverted when we have
removed type casting from Arel in Rail 5.1
2014-12-26 17:48:08 -07:00
Sean Griffin 50d7e448e8 Inform Arel that we don't need additional type casting in batching
Part of the larger refactoring to remove type casting from Arel. We can
inform it that we already have the right type by wrapping the value in
an `Arel::Nodes::Quoted`. This commit can be reverted when we have
removed type casting from Arel in Rail 5.1
2014-12-26 17:45:01 -07:00
Sean Griffin 15e2d5043f Go through normal `update_all` logic when updating lock columns 2014-12-26 17:36:47 -07:00
Sean Griffin 0520e6559e Go through normal `update_all` logic when updating counter caches
Part of a larger refactoring to remove type casting behavior from Arel
2014-12-26 17:30:58 -07:00
Sean Griffin 796574c92c We don't need additional type casting for locking updates
Part of the larger refactoring to remove type casting from Arel. We can
inform it that we already have the right type by wrapping the value in
an `Arel::Nodes::Quoted`. This commit can be reverted when we have
removed type casting from Arel in Rail 5.1
2014-12-26 17:17:01 -07:00
Sean Griffin a61a85683a Inform Arel that we don't need type casting in tests
Part of the larger refactoring to remove type casting from Arel. We can
inform it that we already have the right type by wrapping the value in
an `Arel::Nodes::Quoted`. This commit can be reverted when we have
removed type casting from Arel in Rail 5.1
2014-12-26 17:06:43 -07:00
Sean Griffin 3eb16cea7e Go through normal where logic in `apply_join_dependency`
Part of the larger refactoring to remove type casting from Arel.
2014-12-26 17:02:40 -07:00
Sean Griffin 8ce6fd5594 Inform Arel that we don't need to cast a value in tests
Part of the larger refactoring to remove type casting from Arel. We can
inform it that we already have the right type by wrapping the value in
an `Arel::Nodes::Quoted`. This commit can be reverted when we have
removed type casting from Arel in Rail 5.1
2014-12-26 17:01:05 -07:00
Sean Griffin b4e6e47471 We don't need to type cast the offset in `find_in_batches`
Part of the larger refactoring to remove type casting from Arel. We can
inform it that we already have the right type by wrapping the value in
an `Arel::Nodes::Quoted`. This commit can be reverted when we have
removed type casting from Arel in Rail 5.1
2014-12-26 16:56:24 -07:00
Sean Griffin a11a8ff784 Fall back to type casting from the connection adapter
There are several valid cases where right now we can't determine the
association's class in a call to `where`. In these cases, we can fall
back to casting by looking up the column from the connection adapter
(which is what happens right now when we fall through to Arel)

This is ugly, and since we're trying to separate the concept of a type
from a column, I'd like to remove it in the future. The problem
basically comes down to this:

    Liquid.joins(molecules: :electrons)
      .where("molecules.name" => "something", "electrons.name" => "something")

The hash in this case will turn into:

    {
      molecules: { name: "something" },
      electrons: { name: "something" },
    }

What we actually need is:

    {
      molecules: {
        name: "something",
        electrons: { name: "something" },
      }
    }

/cc @mrgilman
2014-12-26 16:54:12 -07:00
Sean Griffin 5f521cbff3 Go through normal `where` logic in uniqueness validation
This code could use some much heavier refactoring. It looks like
`build_relation` duplicates most of the logic of `Relation#where` and
`PredicateBuilder` with regards to handling associations and attribute
aliases
2014-12-26 16:28:36 -07:00
Sean Griffin efe5986696 We don't need to cast the value a second time in uniqueness validations
Part of the larger refactoring to remove type casting from Arel. Since
we've already cast the value a few lines above, we don't need to re-cast
it later. We can inform Arel of this by wrapping it in an
`Arel::Nodes::Quoted`, which will no longer be required in Rails 5.1
2014-12-26 16:21:38 -07:00
Sean Griffin 0936972634 We don't need to perform type casting on the STI condition
We will always have the correct type for this query, so no casting is
needed. We inform Arel that we already have the right type by wrapping
it in an `Arel::Nodes::Quoted` (which we will no longer need to do in
Rails 5.1)
2014-12-26 16:17:01 -07:00
Sean Griffin b98668decb Go through normal `where` logic when preloading associations
This will allow eager type casting to take place as needed. There
doesn't seem to be any particular reason that the `in` statement was
forced for single values, and the commit message where it was introduced
gives no context.

See
d90b4e2615
2014-12-26 16:12:56 -07:00
Sean Griffin 6d4a19cd50 Eagerly cast array values passed to the predicate builder
Part of a larger refactoring to remove type casting from Arel.

/cc @mrgilman

[Sean Griffin & Melanie Gilman]
2014-12-26 15:57:18 -07:00
Sean Griffin eac4658bb2 Eagerly cast range values in the predicate builder
A custom object is required for this, as you cannot build a range
object out of `Arel::Nodes::Quoted` objects. Depends on the changes
introduced in
cf03bd45e3

/cc @mrgilman
2014-12-26 15:52:57 -07:00
Sean Griffin 3179b4a868 Perform casting of single values within the predicate builder
As part of the larger refactoring to remove type casting from Arel, we
need to do the casting of values eagerly. The predicate builder is the
closest place that knows about the Active Record class, and can
therefore have the type information.

/cc @mrgilman

[Sean Griffin & Melanie Gilman]
2014-12-26 15:33:57 -07:00
Sean Griffin a60770d3bf Remove `klass` and `arel_table` as a dependency of `PredicateBuilder`
This class cares far too much about the internals of other parts of
Active Record. This is an attempt to break out a meaningful object which
represents the needs of the predicate builder. I'm not fully satisfied
with the name, but the general concept is an object which represents a
table, the associations to/from that table, and the types associated
with it. Many of these exist at the `ActiveRecord::Base` class level,
not as properties of the table itself, hence the need for another
object. Currently it provides these by holding a reference to the class,
but that will likely change in the future. This allows the predicate
builder to remain wholy concerned with building predicates.

/cc @mrgilman
2014-12-26 15:19:42 -07:00
Sean Griffin 35362817b1 Fix new warning in ruby 2.2 2014-12-26 15:13:08 -07:00
Sean Griffin 3bbe88ecd7 Refactor association handling in `PredicateBuilder`
I'm attempting to remove `klass` as a dependency of the predicate
builder, in favor of an object that better represents what we're using
it for. The only part of this which doesn't fit nicely into that picture
is the check for an association being polymorphic. Since I'm not yet
sure what that is going to look like, I've moved this logic into another
class in an attempt to separate things that will change from things that
won't.
2014-12-26 14:44:48 -07:00
Sean Griffin 392a453b10 Re-use the predicate builder in the `ArrayHandler`
This reduces the number of places which will need to care about single
value or range specific logic as we introduce type casting. The array
handler is only responsible for producing `in` statements.

/cc @mrgilman

[Sean Griffin & Melanie Gilman]
2014-12-26 14:18:26 -07:00
Sean Griffin a3936bbe21 Change `PredicateBuilder` handler methods to instance methods
This will allow us to pass the predicate builder into the constructor of
these handlers. The procs had to be changed to objects, because the
`PredicateBuilder` needs to be marshalable. If we ever decide to make
`register_handler` part of the public API, we should come up with a
better solution which allows procs.

/cc @mrgilman

[Sean Griffin & Melanie Gilman]
2014-12-26 14:12:16 -07:00
Sean Griffin af55197d86 Add missing `:nodoc:`
We're accidentally documenting `PredicateBuilder` and `ArrayHandler`
since there's a constant which is missing `# :nodoc:`
2014-12-26 14:03:50 -07:00
Sean Griffin 1d6bb77636 Inject the `PredicateBuilder` into the `Relation` instance
Construction of relations can be a hotspot, we don't want to create one
of these in the constructor. This also allows us to do more expensive
things in the predicate builder's constructor, since it's created once
per AR::Base subclass
2014-12-26 13:53:56 -07:00
Sean Griffin ed1a775da3 Remove unused `@relation` instance variable
We don't memoize the relation instance
2014-12-26 13:41:53 -07:00
Sean Griffin f5e6bafe6a Merge branch 'brainopia-remember_frozen_state_in_transaction' 2014-12-26 13:13:27 -07:00
brainopia c6fd246436 Propagate frozen state during transaction changes 2014-12-26 13:11:10 -07:00
Sean Griffin a983e1e89c Correctly ignore `case_sensitive` for UUID uniqueness validation
I think we should deprecate this behavior and just error if you tell us
to do a case insensitive comparison for types which are not case
sensitive. Partially reverts 35592307

Fixes #18195
2014-12-26 13:04:29 -07:00
claudiob d3b098b828 Require Ruby 2.2 for Rails 5.0
Stems from [this comment](https://github.com/rails/rails/pull/18203#issuecomment-68138096) by @robin850
and by the blog post http://weblog.rubyonrails.org/2014/12/19/Rails-4-2-final
2014-12-26 13:53:09 +01:00
Ryuta Kamizono 9b3e7b396e Dump the default `nil` for PostgreSQL UUID primary key. 2014-12-26 17:54:08 +09:00
Vipul A M 1a9e47777c - Changed `target` to `target_reflection` to avoid warning `possible reference to past scope` 2014-12-25 22:40:32 +05:30
Pavel Penkov 290e8e117f Check for Rails.env instead of Rails
`Rails` constant is added by rails-html-sanitizer leading to bugs in
non-Rails apps using ActiveRecord and ActionMailer
2014-12-25 16:34:28 +03:00
Zachary Scott 269a2ea08d Correct grammar to fix #18182 [ci skip] 2014-12-24 16:02:01 -05:00
Sean Griffin 5a2d85be4d Merge pull request #18159 from M7/docs-active_record-update_query_method_docs_with_full_description
Describe full behaviour of Active Record's attribute query methods
2014-12-23 17:42:29 -07:00
Michael D.W. Prendergast c9d86d4148 Clarify that query methods have a custom definition of whether a numeric value is present. [ci skip]
The way Active Record query methods handle numeric values is a special case, and is not part of Rails's standard definition of present. This update attempts to make this more clear in the docs, so that people don't expect Object#present? to return false if used on a number that is zero.
2014-12-23 19:32:49 -05:00
Sean Griffin a862c39b88 Merge pull request #18174 from bogdan/cleanup_has_many_though_association_count
Remove unneeded special case to calculate size for has_many :through
2014-12-23 13:54:34 -07:00
Bogdan Gusiev d03da5948c Remove unneeded special case to calculate size for has_many :through
All cases are properly handled in CollectionAssociation
for all subclasses of this association
2014-12-23 21:28:41 +02:00
Sean Griffin e35221cfd9 Don't treat `nil` as changed in serialized types
We were ignoring the `default_value?` escape clause in the serialized
type, which caused the default value to always be treated as changed.

Fixes #18169
2014-12-23 09:40:01 -07:00
Sean Griffin d26704a15f Refactor a common class to reduce the duplication for `references`
The code for `TableDefinition#references` and
`SchemaStatements#add_reference` were almost identical both
structurally, and in terms of domain knowledge. This removes that
duplication into a common class, using the `Table` API as the expected
interface of its collaborator.
2014-12-23 09:20:54 -07:00
Sean Griffin affae7d904 Fix syntax warning
This isn't Seattle.rb, @senny. ;)
2014-12-23 09:13:56 -07:00
Sean Griffin c81a74c972 Merge pull request #18167 from al2o3cr/checkin_connection_leak
Fix connection leak when a thread checks in additional connections.
2014-12-23 08:37:33 -07:00
Matt Jones 5e024070ab Fix connection leak when a thread checks in additional connections.
The code in `ConnectionPool#release` assumed that a single thread only
ever holds a single connection, and thus that releasing a connection
only requires the owning thread_id.

There is a trivial counterexample to this assumption: code that checks
out additional connections from the pool in the same thread. For
instance:

    connection_1 = ActiveRecord::Base.connection
    connection_2 = ActiveRecord::Base.connection_pool.checkout
    ActiveRecord::Base.connection_pool.checkin(connection_2)
    connection_3 = ActiveRecord::Base.connection

At this point, connection_1 has been removed from the
`@reserved_connections` hash, causing a NEW connection to be returned as
connection_3 and the loss of any tracking info on connection_1. As long
as the thread in this example lives, connection_1 will be inaccessible
and un-reapable. If this block of code runs more times than the size of
the connection pool in a single thread, every subsequent connection
attempt will timeout, as all of the available connections have been
leaked.

Reverts parts of 9e457a8654 and
essentially all of 4367d2f05c
2014-12-23 09:54:52 -05:00
Sean Griffin e550bbf8fc Changelog for 99a6f9e60e
Here you go, @senny. 😁
2014-12-23 07:21:43 -07:00
Sean Griffin b994c0e03d Merge pull request #18145 from georgemillo/patch-2
Add information about "allow_destroy" requiring an ID. [ci skip]
2014-12-23 07:17:01 -07:00
Sean Griffin a054269ff8 Merge Pull Request #18157
Conflicts:
	activerecord/CHANGELOG.md
2014-12-23 07:13:54 -07:00
Yves Senn b5bfd6fe52 docs, replace ` with + for proper rdoc output. [ci skip] 2014-12-23 13:36:13 +01:00
Yves Senn ad783136d7 Replace deprecated `#load_schema` with `#load_schema_for`. 2014-12-23 12:07:15 +01:00
George Millo 7476b90e16 Add information about "allow_destroy" requiring an ID. [ci skip]
I just wasted an absurd amount of time trying to figure out why my model
wasn't being deleted even though I was setting `_destroy` to true like
the instructions said. Making the documentation a little bit clear so
that someone like me doesn't waste their time in future.
2014-12-23 10:18:02 +00:00
Yves Senn 0587070391 cleanup CHANGELOGs. [ci skip] 2014-12-23 08:56:17 +01:00
Michael D.W. Prendergast e35432689e Clarify that the word present refers to Object#present?. [ci skip]
Update Active Record's attribute query methods documentation to clarify that whether an attribute is present is based on Object#present?. This gives people a place to go see what the exact definition of presence is. [ci skip]
2014-12-23 01:54:40 -05:00
Daniel Fox 2859341c38 Fixing numeric attrs when set to same negative value
This bug occurs when an attribute of an ActiveRecord model is an
ActiveRecord::Type::Integer type or a ActiveRecord::Type::Decimal type (or any
other type that includes the ActiveRecord::Type::Numeric module. When the value
of the attribute is negative and is set to the same negative value, it is marked
as changed.

Take the following example of a Person model with the integer attribute age:

    class Person < ActiveRecord::Base
      # age          :integer(4)
    end

The following will produce the error:

    person = Person.new(age: -1)
    person.age = -1
    person.changes
    => { "age" => [-1, -1] }
    person.age_changed?
    => true

The problematic line is here:

    module ActiveRecord
      module Type
        module Numeric
          ...

          def non_numeric_string?(value)
            # 'wibble'.to_i will give zero, we want to make sure
            # that we aren't marking int zero to string zero as
            # changed.
            value.to_s !~ /\A\d+\.?\d*\z/
          end
        end
      end
    end

The regex match doesn't accept numbers with a leading '-'.
2014-12-23 00:19:14 -06:00
Michael D.W. Prendergast 0ce7840b9b Update Active Record's attribute query methods documentation to describe its full behaviour. [ci skip] 2014-12-22 22:28:45 -05:00
Grey Baker d318badc26 Don't raise on out-of-range datetimes passed by a user 2014-12-23 02:35:12 +00:00
Sean Griffin be2b98b4ae Improve the performance of reading belongs_to associations
`ActiveRecord::Base#[]` has overhead that was introduced in 4.2. The
`foo["id"]` working with PKs other than ID isn't really a case that we
want to support publicly, but deprecating was painful enough that we
avoid it. `_read_attribute` was introduced as the faster alternative for
use internally. By using that, we can save a lot of overhead. We also
save some overhead by reading the attribute one fewer times in
`stale_state`.

Fixes #18151
2014-12-22 16:38:38 -07:00
Sean Griffin fb160f6e7d Don't perform statement caching for `find` when called from a scope
If there is a method defined such as `find_and_do_stuff(id)`, which then
gets called on an association, we will perform statement caching and the
parent ID will not change on subsequent calls.

Fixes #18117
2014-12-22 15:38:58 -07:00
Sean Griffin 18ae0656f5 Don't calculate all in-place changes to determine if attribute_changed?
Calling `changed_attributes` will ultimately check if every mutable
attribute has changed in place. Since this gets called whenever an
attribute is assigned, it's extremely slow. Instead, we can avoid this
calculation until we actually need it.

Fixes #18029
2014-12-22 14:55:58 -07:00
Sean Griffin 849274316d Don't wrap `create_table` in a transaction for tests which run on MySQL
PG will warn without it, but mysql2 errors out.
2014-12-22 14:15:56 -07:00
Sean Griffin a03ea684ef Use the new `foreign_key` option on `references` in generators
Changes `rails g model Post user:references` from

    def change
      create_table :posts do |t|
        t.references :user, index: true
      end

      add_foreign_key :posts, :users
    end

to

    def change
      create_table :posts do |t|
        t.references :user, index: true, foreign_key: true
      end
    end

Changes `rails g migration add_user_to_posts user:references` from

    def change
      add_reference :posts, :users, index: true
      add_foreign_key :posts, :users
    end

to

    def change
      add_reference :posts, :users, index: true, foreign_key: true
    end
2014-12-22 13:47:11 -07:00
Sean Griffin 82afeaf23b Add `foreign_key` as an option to `references` for `change_table`
This has the same comments as 9af90ffa00ba35bdee888e3e1ab775ba0bdbe72c,
however it affects the `add_reference` method, and `t.references` in the
context of a `change_table` block.

There is a lot of duplication of code between creating and updating
tables. We should re-evaluate the structure of this code from a high
level so changes like this don't need to be made in two places. (Note to
self)
2014-12-22 13:47:11 -07:00
Sean Griffin 68a6c8ecc4 Convert `add_references` to use kwargs
While we still aren't accepting PRs that only make changes like this,
it's fine when we're actively working on a method if it makes our lives
easier.
2014-12-22 13:47:11 -07:00
Sean Griffin 99a6f9e60e Add a `foreign_key` option to `references` while creating the table
Rather than having to do:

    create_table :posts do |t|
      t.references :user
    end

    add_foreign_key :posts, :users

You can instead do:

    create_table :posts do |t|
      t.references :user, foreign_key: true
    end

Similar to the `index` option, you can also pass a hash. This will be
passed as the options to `add_foreign_key`. e.g.:

    create_table :posts do |t|
      t.references :user, foreign_key: { primary_key: :other_id }
    end

is equivalent to

    create_table :posts do |t|
      t.references :user
    end

    add_foreign_key :posts, :users, primary_key: :other_id
2014-12-22 13:47:10 -07:00
Sean Griffin a9c0c46263 Convert `references` to kwargs
While we aren't taking PRs with these kinds of changes just yet, they
are fine if we're actively working on the method and it makes things
easier.
2014-12-22 13:47:10 -07:00
Sean Griffin 32f30d22d5 Add `force: true` to table created in tests
If the test is interrupted in a way that the teardown block fails to
run, the tests will fail to run until the table is removed manually
without this option.
2014-12-22 12:49:34 -07:00
Sean Griffin b0f2b94dd3 Correctly handle limit on int4 and int8 types in PG
PG doesn't register it's types using the `int(4)` format that others do.
As such, if we alias `int8` to the other integer types, the range
information is lost. This is fixed by simply registering it separately.

The other option (which I specifically chose to avoid) is to pass the
information of the original type that was being aliased as an argument.
I'd rather avoid that, since an alias should truly be treated the same.
If we need different behavior for a different type, we should explicitly
register it with that, and not have a conditional based on aliasing.

Fixes #18144

[Sean Griffin & ysbaddaden]
2014-12-22 09:55:41 -07:00
Sean Griffin 41f1323e74 Correctly handle Float -> BigDecimal with unspecified precision
Fixes #18122
2014-12-22 07:08:31 -07:00
Sammy Larbi f5489f9ab4 Clarify ActiveRecord testing guidelines [ci skip]
1. Specify that you need to create the test databases, and that no special
   Rails command needs to be run to do that.
2. Although the underscore style of `rake test_mysql` works, make the
   documentation of running the tests in RUNNING_UNIT_TESTS.rdoc
   consistent with the "Contributing..." guide.
3. Promote "Testing Active Record" to not be a subsection of
   "Running a Single Test," since it doesn't make sense as a subsection
   of that.
2014-12-21 10:18:46 -06:00
Zachary Scott e8e4e72639 Fixed syntax error in RDoc directive 2014-12-20 10:28:08 -08:00
Arthur Nogueira Neves 155a21fe01 Merge pull request #18092 from nippysaurus/clarity_batch_starting_point
Update description for `start` parameter.
2014-12-20 13:16:56 -05:00
Prathamesh Sonpatki 5ef713c53c Allow ActiveRecord::Relation#update to run on result of a relation with callbacks and validations
- Right now, there is no method to update multiple records with
  validations and callbacks.
- Changed the behavior of existing `update` method so that when `id`
  attribute is not given and the method is called on an `Relation`
  object, it will execute update for every record of the `Relation` and
  will run validations and callbacks for every record.
- Added test case for validating that the callbacks run when `update` is
  called on a `Relation`.
- Changed test_create_columns_not_equal_attributes test from
  persistence_test to include author_name column on topics table as it
  it used in before_update callback.
- This change introduces performance issues when a large number of
  records are to be updated because it runs UPDATE query for every
  record of the result. The `update_all` method can be used in that case
  if callbacks are not required because it will only run single UPDATE
  for all the records.
2014-12-20 15:33:18 +05:30
Arthur Nogueira Neves e4f015e4e8
Merge pull request #18102 from arthurnn/nodoc_constant
Add nodoc to some constants [skip ci]
2014-12-19 18:22:46 -05:00
Yves Senn be1e0241f0 `force: :cascade` to recreate tables referenced by foreign-keys. 2014-12-19 11:27:04 +01:00
Michael Dawson d557f1bac0 Clarity start parameter
I find that `Specifies the starting point for the batch processing.`
does not give enough information for me to understand what this
parameter actually does.
2014-12-19 15:42:40 +10:00
Yves Senn 36ce0c2c82 `db:structure:load` and `db:schema:load` no longer purge the database.
Closes #17945

`db:test:prepare` still purges the database to always keep the test
database in a consistent state.

This patch introduces new problems with `db:schema:load`. Prior
to the introduction of foreign-keys, we could run this file against
a non-empty database. Since every `create_table` containted the
`force: true` option, this would recreate tables when loading the schema.

However with foreign-keys in place, `force: true` wont work anymore and
the task will crash.

/cc @schneems
2014-12-18 10:08:17 +01:00
Godfrey Chan c115a84c8b Relax the UUID regex
Apparently PG does not validate against RFC 4122. The intent of the original
patch is just to protect against PG errors (which potentially breaks txns, etc)
because of bad user input, so we shouldn't try any harder than PG itself.

Closes #17931
2014-12-18 00:51:05 -08:00
korbin 27955b4bb1 fix issue with reaping_frequency type
When using DATABASE_URL to configure ActiveRecord, :reaping_frequency
does not get converted from a string to a numeric value. This value is
eventually passed to 'sleep' and must be numeric to avoid exceptions.

This commit converts :reaping_frequency to a float when present.
2014-12-17 19:45:31 -07:00
Ryuta Kamizono 7da314bb03 Remove unused line 2014-12-17 19:38:32 +09:00
Sean Griffin dd8b5fb9d3 `update_column` take ruby-land input, not database-land input
In the case of serialized columns, we would expect the unserialized
value as input, not the serialized value. The original issue which made
this distinction, #14163, introduced a bug. If you passed serialized
input to the method, it would double serialize when it was sent to the
database. You would see the wrong input upon reloading, or get an error
if you had a specific type on the serialized column.

To put it another way, `update_column` is a special case of
`update_all`, which would take `['a']` and not `['a'].to_yaml`, but you
would not pass data from `params` to it.

Fixes #18037
2014-12-16 15:23:05 -07:00
eileencodes 80099618e4 Pass connection rather than alias_tracker
Because we're only using the `connection` so passing the entire tracker
isn't unnecessary.

Eventually only the `connection` will be passed to `add_constraints`
with later refactoring but curretly that's not possible because of
`construct_tables` method.
2014-12-13 09:10:29 -05:00
Sean Griffin 6cb956592c Add test case for joined pluck
39542fba54 (commitcomment-8938379)
2014-12-11 14:54:03 -07:00
Sean Griffin 39542fba54 Improve the test case introduced by bd0d47e 2014-12-11 13:34:46 -07:00
Sean Griffin 387065a023 Merge pull request #17994 from mfazekas/pluck-bind-values-master
Fix ProtocolViolation/bind message for polymorphic + pluck or group+calc
2014-12-11 13:25:22 -07:00
Sean Griffin c0c6dd6aa2 Merge pull request #17793 from kamipo/fix_undesirable_range_error
Fix undesirable RangeError by Type::Integer. Add Type::UnsignedInteger.
2014-12-11 11:04:37 -07:00
Ryuta Kamizono b61a93b44e Fix undesirable RangeError by Type::Integer. Add Type::UnsignedInteger. 2014-12-12 00:35:48 +09:00
Ryuta Kamizono cb07e63ba8 Refactor `quoted_date`
Move microseconds formatting to `AbstractAdapter`.
2014-12-11 19:45:01 +09:00
Miklos Fazkeas bd0d47eed6 Fix ProtocolViolation/bind message supplies for polymorphic + pluck or group 2014-12-11 00:48:06 +01:00
Rafael Mendonça França 81e940c313 Merge pull request #17970 from ulissesalmeida/foreign-type-has-many-has-one
Add foreign_type option for polymorphic has_one and has_many.
2014-12-10 19:15:07 -02:00
Akira Matsuda 8e52954349 Unused csv fixture file 2014-12-09 18:54:07 +09:00
Carlos Antonio da Silva 57a6d80515 Merge pull request #17972 from claudiob/remove-unused-callback-fixtures
Remove unused "Developer" fixtures from tests
2014-12-09 07:38:58 -02:00
Sean Griffin 65588b7463 Update test case for TZ aware attributes
The test added in 42418cfc94 wasn't
actually testing anything, since the bug was with TZ aware attributes
only.
2014-12-08 15:06:11 -07:00
Sean Griffin 42418cfc94 Allow custom handling of non-standard types in `time_zone_conversion`
PostgreSQL for example, allows infinity as a valid value for date time
columns. The PG type has explicit handling for that case. However, time
zone conversion will end up trampling that handling. Unfortunately, we
can't call super and then convert time zones.

However, if we get back nil from `.in_time_zone`, it's something we
didn't expect so we can let the superclass handle it.

Fixes #17971
2014-12-08 14:52:06 -07:00
claudiob 3502e6ed7c Remove unused "Developer" fixtures from tests
The `RecursiveCallbackDeveloper` and `ImmutableMethodDeveloper` classes
are not used anymore in tests, and neither is the `@cancelled` variable.
2014-12-08 13:07:56 -08:00
Ulisses Almeida + Kassio Borges 075c81feec Add foreign_type option for polymorphic has_one and has_many.
To be possible to use a custom column name to save/read the polymorphic
associated type in a has_many or has_one polymorphic association, now users
can use the option :foreign_type to inform in what column the associated object
type will be saved.
2014-12-08 18:13:15 -02:00
Sean Griffin 7daeb98c76 Don't error when `attributes` is called on a frozen AR model
`freeze` will ultimately end up freezing the `AttributeSet`, which in
turn freezes its `@attributes` hash. However, we actually insert a
special object to lazily instantiate the values of the hash on demand.
When it does need to actually instantiate all of them for iteration (the
only case is `ActiveRecord::Base#attributes`, which calls
`AttributeSet#to_h`), it will set an instance variable as a performance
optimization

Since it's just an optimization for subsequent calls, and that method
being called at all is a very uncommon case, we can just leave the ivar
alone if we're frozen, as opposed to coming up with some overly
complicated mechanism for freezing which allows us to continue to modify
ourselves.

Fixes #17960
2014-12-08 12:48:24 -07:00
Sean Griffin 4ed60af60d Revert to 4.1 behavior for casting PG arrays
The user is able to pass PG string literals in 4.1, and have it
converted to an array. This is also possible in 4.2, but it would remain
in string form until saving and reloading, which breaks our
`attr = save.reload.attr` contract. I think we should deprecate this in
5.0, and only allow array input from user sources. However, this
currently constitutes a breaking change to public API that did not go
through a deprecation cycle.
2014-12-08 11:42:29 -07:00
Rafael Mendonça França 7fb809c033 Merge pull request #17964 from carols10cents/improve-after-commit-argumenterror-message
Make error message clearer that :on requires a symbol, not a string
2014-12-08 15:19:23 -02:00
Zachary Scott 04bf9fbeda Fix type case of "validations" and word-wrap from #17954 [ci skip] 2014-12-08 08:36:04 -08:00
Mike Chau 34a8a149c6 Add note to Store about uniqueness validation (#17954) [skip ci] 2014-12-08 02:30:49 -06:00
Carol Nichols ffce60e128 Make error message clearer that :on requires a symbol, not a string
The validation added in 5a3dc8092d will
reject values for the `:on` option for after_commit and after_rollback
callbacks that are string values like `"create"`.

However, the error message says ":on conditions for after_commit and
after_rollback callbacks have to be one of create,destroy,update". That
looks like a string value *would* be valid.

This commit changes the error message to say ":on conditions for
after_commit and after_rollback callbacks have to be one of [:create,
:destroy, :update]", making it clearer that symbols are required.
2014-12-07 22:16:00 -05:00
Neeraj Singh 6125221da6 minor sentences fixes 2014-12-07 22:02:02 -05:00
eileencodes 480e911859 Fix grammar of sentence in Reflection documentation 2014-12-07 13:36:05 -05:00
Sean Griffin 785d04e310 Add `force: true` to tables created in PG tests
If the tests are interupted and the teardown block doesn't run, the
developer needs to delete these manually in order to be able to run the
tests again.
2014-12-05 15:54:12 -07:00
Sean Griffin 670e7941d5 Correctly respect subtypes for PG arrays and ranges
The type registration was simply looking for the OID, and eagerly
fetching/constructing the sub type when it was registered. However,
numeric types have additional parameters which are extracted from the
actual SQL string of the type during lookup, and can have their behavior
change based on the result.

We simply need to use the block form of registration, and look up the
subtype lazily instead.

Fixes #17935
2014-12-05 15:34:30 -07:00
Sean Griffin bbbe9cfc61 Merge pull request #17919 from mrgilman/stop-supporting-nested-arrays
Remove deprecated behavior allowing nested arrays as query values
2014-12-04 15:54:45 -07:00
Sean Griffin d1f003e67b Correctly handle multiple attribute method prefix/suffixes which match
Active Record defines `attribute_method_suffix :?`. That suffix will
match any predicate method when the lookup occurs in Active Model. This
will make it incorrectly decide that `id_changed?` should not exist,
because it attempts to determine if the attribute `id_changed` is
present, rather than `id` with the `_changed?` suffix. Instead, we will
look for any correct match.
2014-12-04 15:50:31 -07:00
Sean Griffin 08ff4ccbbb Merge pull request #17920 from calebthompson/dont-rely-on-environment-task-for-schema-load
Remove environment dependency for db:schema:load
2014-12-04 14:17:02 -07:00
Melanie Gilman be6897e34d Remove deprecated behavior allowing nested arrays as query values 2014-12-04 16:13:00 -05:00
Caleb Thompson 382a70c875
Remove environment dependency for db:schema:load
All of the behavior :environment was giving (that db:schema:load needed)
was provided as well with :load_config.

This will address an issue introduced in
https://github.com/rails/rails/pull/15394. The fact that db:schema:load
now drops and creates the database causes the Octopus gem to have [an
issue](https://github.com/tchandy/octopus/issues/273) during the drop
step for the test database (which wasn't happening in db:schema:load
before). The error looks like:

    ActiveRecord::StatementInvalid: PG::ObjectInUse: ERROR:  cannot drop the currently open database
    : DROP DATABASE IF EXISTS "app_test"

Because of the timing, this issue is present in master, 4-2-*, and
4.1.8.

A note to forlorn developers who might see this: "Additionally" in a
commit message means you should have a separate commit, with a separate
justification for changes. Small commits with big messages are your
friends.
2014-12-04 14:11:02 -07:00
Melanie Gilman c0609dd0f0 Deprecate `Class` handler in `PredicateBuilder`
Users should pass strings to queries instead of classes
2014-12-04 15:06:21 -05:00
Rafael Mendonça França 28beb286b3 Merge pull request #17906 from kamipo/prevent_symbol_gc
Prevent Symbol GC
2014-12-04 13:26:27 -02:00
Yves Senn 9e0dab64d8 docs, bring back `ActiveRecord::Core` methods in the API. [ci skip]
This `# :nodoc:` had the effect of hiding every method that follows.
This meant that the API page for `ActiveRecord::Core` only contained
`configurations` and none of the following methods.

Furthermore this `# :nodoc:` had no effect on `maintain_test_schema`.
Those `mattr_accessor` inside the `included` block are not picked up
by rdoc.

/cc @zzak
2014-12-04 09:07:56 +01:00
Ryuta Kamizono 8dcfc5d081 Prevent Symbol GC 2014-12-04 11:47:22 +09:00
Isaac Seymour db64f5d7eb Clarify that batching methods can be used with any orderable type primary key, not just integer ones, as per @a58cafeb3a86be46849de57481b6644094fb8165 2014-12-03 21:56:14 +00:00
Sean Griffin b612df9a25 Merge pull request #17898 from mrgilman/move-predicate-builder-to-constructor
Move PredicateBuilder instantiation to constructor
2014-12-03 11:31:45 -07:00
Yves Senn 94e8fc0619 Active Record changelog needs to keep pointing at 4-2-stable. #17651
[ci skp]
2014-12-03 19:29:26 +01:00
Yves Senn 3f78a57fd6 docs, add new changelog entries at the top 😓 [ci skip] #17651 2014-12-03 19:27:13 +01:00
Yves Senn 2ee8c9c5b7 Merge pull request #17651 from CLUSTERfoo/fix/adding_timestamps_migration_not_reversible
Failure to rollback t.timestamps when within a change_table migration
2014-12-03 19:22:55 +01:00
Melanie Gilman 286ab9b606 Move PredicateBuilder instantiation to constructor
In order to maintain thread safety and prevent race condition from memoization.
2014-12-03 13:20:56 -05:00
noam b64fb3020b Failure to rollback t.timestamps when within a change_table migration
When running the following migration:

    change_table(:table_name) { |t| t/timestamps }

The following error was produced:

    wrong number of arguments (2 for 1) .... /connection_adapters/abstract/schema_statements.rb:851:in `remove_timestamps'

This is due to `arguments` containing an empty hash as its second
argument.
2014-12-03 11:35:40 -05:00
Yves Senn 6613716ad7 document that `.delete` does work on `#readonly?` records. Closes #11860
[ci skip]

This is due to the fact that `.delete` is directly translated to SQL.
It tries to follow the same rules as `.delete_all` which is not able
to verify that records are `#readonly?`.
2014-12-03 17:31:25 +01:00
Yves Senn 497544f0b3 skip test to get `sqlite3_mem` suite passing. 2014-12-03 11:38:37 +01:00
Yves Senn 19dfd2f8ed Merge pull request #17890 from sergey-alekseev/remove-useless-methods
remove useless methods
2014-12-03 08:25:40 +01:00
Sean Griffin 930d0853f4 Merge pull request #17889 from mxie/mx-fix-nonexistent-typo
Fix "nonexistent" typo in tests
2014-12-02 17:39:50 -07:00
Sergey Alekseev 44919e1cf0 remove useless methods 2014-12-03 03:20:55 +03:00
Melissa Xie 3b43d1d822 Fix "nonexistent" typo in tests 2014-12-02 19:19:10 -05:00
Sean Griffin f987609ad6 Require missing association in test 2014-12-02 16:23:26 -07:00
Melanie Gilman fcc3cbc71f Refactor `build_from_hash` to convert dot notation to hash first
This ensures that we're handling all forms of nested tables the same way.

We're aware that the `convert_dot_notation_to_hash` method will cause a
performance hit, and we intend to come back to it once we've refactored some of
the surrounding code.

[Melissa Xie & Melanie Gilman]
2014-12-02 15:49:16 -05:00
Sean Griffin 3317d6958c Merge pull request #17886 from mrgilman/refactor-predicate-builder
Refactor `PredicateBuilder` from singleton to instance
2014-12-02 11:45:12 -07:00
Melanie Gilman 502bc87fba Refactor `PredicateBuilder` from singleton to instance 2014-12-02 11:04:38 -05:00
deeeki 66b84c9f44 Allow to unscope where conditions using `arel_table` with Symbol
This commit fixes the following case.

    User.where(User.arel_table[:created_at].lteq(1.year.ago)).unscope(where :created_at)
2014-12-03 00:20:01 +09:00
Yves Senn 9e4ed2f996 no need to pass native_database_types around 2014-12-02 13:36:46 +01:00
Yves Senn 780269c732 pg tests, get rid of global schema `schema_1`. 2014-12-02 12:08:52 +01:00
Yves Senn 90e396ce65 pg tests, move uniqueness validation test to array tests. 2014-12-02 11:53:18 +01:00
Yves Senn b8ec014b2d tests, extract pg number tests into separate file. 2014-12-02 11:46:08 +01:00
Yves Senn af7c6e493c tests, move schema shorthand assertions into pg specific tests. 2014-12-02 11:35:53 +01:00
Yves Senn bcf5b281a8 tests, move pg geometric tests out of `base_test`. 2014-12-02 11:00:19 +01:00
Aaron Patterson e47b523fae ugh, forgot to add this test to cdd90f39d7 2014-12-01 11:46:57 -08:00
Yves Senn bec9e83359 tests, favor public API over inspecting columns where possible.
This is a follow up to 07786c5e75
and cd2596f55e
2014-12-01 16:57:48 +01:00
Florian Weingarten c753ede62c Restore query cache on rollback 2014-12-01 15:45:50 +00:00
Yves Senn 07786c5e75 tests, run numeric default tests for every adapter. 2014-12-01 16:26:40 +01:00
Yves Senn cd2596f55e tests, use public API to verify default parsing. #17863, #17856 2014-12-01 16:07:57 +01:00
Guo Xiang Tan 0270363f5c Fix value extracted from negative integers for PostgreSQL.
Fixes: https://github.com/rails/rails/issues/17856.
2014-12-01 22:00:04 +08:00
Sean Griffin 704c658531 Ensure numericality validations work with mutation
The detection of in-place changes caused a weird unexpected issue with
numericality validations. That validator (out of necessity) works on the
`_before_type_cast` version of the attribute, since on an `:integer`
type column, a non-numeric string would type cast to 0.

However, strings are mutable, and we changed strings to ensure that the
post type cast version of the attribute was a different instance than
the before type cast version (so the mutation detection can work
properly).

Even though strings are the only mutable type for which a numericality
validation makes sense, special casing strings would feel like a strange
change to make here. Instead, we can make the assumption that for all
mutable types, we should work on the post-type-cast version of the
attribute, since all cases which would return 0 for non-numeric strings
are immutable.

Fixes #17852
2014-12-01 05:31:44 -07:00
Hendy Tanata 6874133f9e Fix grammar on ActiveRecord::AttributeMethods doc.
[ci skip]
2014-11-30 10:26:13 +00:00
Sean Griffin a975407a0a Update Arel usage for rails/arel#98fc259
`where_sql` now requires that we pass it an engine. None of the manager
classes take an engine in their constructor.
2014-11-29 17:23:10 -07:00
Sean Griffin de239066e3 Stop using `Arel::Table.engine`
We never actually make use of it on the table, since we're constructing
the select manager manually. It looks like if we ever actually were
grabbing it from the table, we're grossly misusing it since it's meant
to vary by AR class.

Its existence on `Arel::Table` appears to be purely for convenience
methods that are never used outside of tests. However, in production
code it just complicates construction of the tables on the rails side,
and the plan is to remove it from `Arel::Table` entirely. I'm not
convinced it needs to live on `SelectManager`, etc either.
2014-11-29 15:49:18 -07:00
Erik Michaels-Ober d1374f99bf Pass symbol as an argument instead of a block 2014-11-29 11:53:24 +01:00
claudiob 96d0f751f9 Bump required Ruby version to 2.1.0
[This article](http://weblog.rubyonrails.org/2014/8/20/Rails-4-2-beta1/#maintenance-consequences-and-rails-5-0) states that:

> Rails 5.0 is in most likelihood going to target Ruby 2.2.

Before the exact minimum version is fully decided, @arthurnn [suggests](https://github.com/rails/rails/pull/17830#issuecomment-64940383)
that **at least** version 2.1.0 **must** be required by the `gemspec` files.
2014-11-28 22:59:51 -08:00
Rafael Mendonça França b2566429fe Merge pull request #17799 from kamipo/refactor_add_column_options
Refactor `add_column_options!`, to move the quoting of default value for :uuid in `quote_value`.
2014-11-28 17:13:30 -02:00
Rafael Mendonça França f25ad07f5a Start Rails 5 development 🎉
We will support only Ruby >= 2.1.

But right now we don't accept pull requests with syntax changes to drop
support to Ruby 1.9.
2014-11-28 15:00:06 -02:00
Thorsten Ball 6405a03c13 Adds preloaded_records method to NullPreloader
This fixes a regression where preloading association throws an
exception if one of the associations in the preloading hash doesn't
exist for one record.

Fixes #16070
2014-11-28 13:42:50 +01:00
Rafael Mendonça França 2cdd229fc2 Merge pull request #17808 from yuki24/fix-bug-where-record-not-saved-loses-error-message
Fixed a bug where AR::RecordNotSaved loses the given error message
2014-11-28 10:29:03 -02:00
Yves Senn f2d602b229 Merge pull request #17798 from kamipo/refactor_visit_add_column
Refactor `SchemaCreation#visit_AddColumn`
2014-11-28 11:13:26 +01:00
Ryuta Kamizono 66cc7ce67c Rename to `quote_default_expression` from `quote_value` 2014-11-28 17:30:55 +09:00
Ryuta Kamizono 91fca372b1 Refactor `add_column_options!`, to move the quoting of default value for :uuid in `quote_value`. 2014-11-28 11:21:08 +09:00
Yuki Nishijima 5142d54114 Fix a bug where AR::RecordNotSaved loses error messages
Since 3e30c5d, it started ignoring the given error message. This commit
changes the behavior of AR::RecordNotSaved#initialize so that it no
longer loses the given error message.
2014-11-27 17:56:12 -08:00
Rafael Mendonça França 200b9035da Merge pull request #17807 from jvperrin/correct-integer-test
Correct test description for large integer test
2014-11-27 21:16:55 -02:00
Rafael Mendonça França 8fc7eb5f21 Update the StatementCache documentation 2014-11-27 14:40:19 -02:00
Rafael Mendonça França 07f4bd5b60 StatementCache is private API
It should not be used in applications
2014-11-27 13:50:10 -02:00
Ryuta Kamizono 9e6733d5f7 Refactor `SchemaCreation#visit_AddColumn` 2014-11-27 21:27:34 +09:00
Recursive Madman 59190c0379 various error classes: added newlines & removed :nodoc: flag from public attribute. 2014-11-26 15:07:35 +01:00
Rafael Mendonça França cb23d6a5ee Merge pull request #17674 from recursive-madman/activerecord-error-improvement
Add #record attribute to RecordNotFound and RecordDestroyed exceptions.
2014-11-26 11:54:15 -02:00
Recursive Madman 3e30c5d422 Add #record attribute to RecordNotFound and RecordDestroyed exceptions.
This allows these exceptions to be handled generically in conjunction with RecordInvalid.
2014-11-26 14:41:49 +01:00
Jon Atack 35c5f47d97 Active Record change log pass [skip ci] 2014-11-26 12:23:00 +01:00
Derek Prior 323334a775 Generators add foreign keys on references
If you run a generator such as:

```
rails generate model accounts supplier:references
```

The resulting migration will now add the corresponding foreign key
constraint unless the reference was specified to be polymorphic.
2014-11-25 20:22:58 -02:00
Sean Griffin e6089029c4 Merge pull request #17697 from sgrif/sg-remove-is-a-check-when-ignoring-tables
Remove is_a? check when ignoring tables
2014-11-25 15:08:55 -07:00
Rafael Mendonça França 25c85cb6f6 Use released arel 2014-11-25 19:58:08 -02:00
Sean Griffin d74e716b48 Move PG float quoting to the correct location
Not sure how we missed this case when we moved everything else to the
`_quote` method.
2014-11-25 13:58:26 -07:00
Yves Senn 208908f00d Merge pull request #17739 from rails/bring_back_db_test_prepare
bring back `db:test:prepare`.
2014-11-25 19:08:43 +01:00
Sean Griffin dd986814e7 Setting an association replaces records with the same id in memory
The records weren't being replaced since equality in Active Record is
defined in terms of `id` only. It is reasonable to expect that the
references would be replaced in memory, even if no queries are actually
executed. This change did not appear to affect any other parts of the
code base. I chose not to execute callbacks since we're not actually
modifying the association in a way that will be persisted.

Fixes #17730
2014-11-25 11:07:24 -07:00
Yves Senn 5c4495538b bring back `db:test:prepare`.
This reverts deprecations added in #13528.
The task is brought back for two reasons:
  1. Give plugins a way to hook into the test database initialization process
  2. Give the user a way to force a test database synchronization

While `test:prepare` is still a dependency of every test task, `db:test:prepare`
no longer hooks into it. This means that `test:prepare` runs before the schema
is synchronized. Plugins, which insert data can now hook into `db:test:prepare`.

The automatic schema maintenance can't detect when a migration is rolled-back,
modified and reapplied. In this case the user has to fall back to `db:test:prepare`
to force the synchronization to happen.
2014-11-25 18:17:01 +01:00
Yves Senn 9e9793b440 do not trigger AR lazy load hook before initializers ran.
[Rafael Mendonça França & Yves Senn]

This require caused the `active_record.set_configs` initializer to
run immediately, before `config/initializers`. This means that setting any
configuration on `Rails.application.config.active_record` inside of
an initializer had no effects when rails was loaded through `rake`.

Introduced by #6518

/cc @rafaelfranca
2014-11-25 18:16:41 +01:00
Santiago Pastorino 33a068299b Merge pull request #17754 from eileencodes/refactor-aliased_table_for
Combine aliased_table_for and aliased_name_for
2014-11-25 12:55:34 -02:00
Ryuta Kamizono 03c1055b74 Fix out of range error message 2014-11-25 19:48:09 +09:00
eileencodes 9e7037f198 Combine aliased_table_for and aliased_name_for
This refactoring reduces the number of conditionals needed to build
`aliased_table_for` and removes `aliased_name_for` because it's no
longer necessary.

`aliased_name_for` was also used in `JoinDependency#initialize` so
that was replaced with `aliased_table_for` as well.
2014-11-24 19:05:45 -05:00
Aaron Patterson cdd90f39d7 allow types to be passed in for USING casts
This allows us so abstract the migration from the type that is actually
used by Rails.  For example, ":string" may be a varchar or something,
but the framework does that translation, and the app shouldn't need to
know.
2014-11-24 14:29:04 -08:00
Aaron Patterson 63963801c0 oops, forgot to add the real assertion! 2014-11-24 14:18:33 -08:00
Aaron Patterson fbef981fdc allow the "USING" statement to be specified on change column calls 2014-11-24 14:15:56 -08:00
Rafael Mendonça França 9f33e3daab Merge pull request #17682 from ReneB/docs/update_all
Explain that default_scope also influences update_all
2014-11-24 19:46:00 -02:00
claudiob 83821e2c4a Mark comments that should not be in the docs
Some comments that are meant to separate blocks of code in a file show up
on http://api.rubyonrails.org as though they were part of the documentation.

This commit hides those comments from the documentation.

Stems from the discussion with @zzak at https://github.com/voloko/sdoc/issues/79#issuecomment-64158738

[ci skip]
2014-11-24 10:55:01 -08:00
Sean Griffin 72e8442797 Ensure the type map's cache is thread safe
Thanks to @thedarkone for pointing out that an instance of this object
is used in a shared context.
2014-11-24 11:24:31 -07:00
Santiago Pastorino e3acd74fa8 Merge pull request #17678 from siddharth28/includes_with_scope_with_joins
Fix includes on association with a scope
2014-11-24 14:55:34 -02:00
René van den Berg 91c0c27769 Reword documentation for update_all
It now contains a carefully formulated reference to the "current relation" which might help clarify that the receiving will generate its own scope, escaping the need for explicitly referencing `default_scope` which is, after all, just another way of specifying a scope and nothing special.
2014-11-24 16:03:07 +01:00
Yves Senn 77fbc53586 cleanup, remove trailing whitespace [ci skip] 2014-11-24 12:14:47 +01:00