Commit Graph

13165 Commits

Author SHA1 Message Date
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
Zachary Scott be8d1a9b57 Add a test for reflection keys as Strings, fixes #16928
See also PR: #17610
2014-11-23 12:06:57 -08:00
Arthur Neves 31b3069615
Update reflections public API doc 2014-11-22 20:33:00 -05:00
Arthur Neves 5dc598814e
Add changelog entry for .reflections API change
`.reflections` public API changed to return a String instead of a Symbol
as keys.

see commit 1f31488499 and 6259e4e2dc

[fixes #16928]
[fixes #17610]
2014-11-22 20:29:29 -05:00
Sean Griffin 6cd9e2bd29 Fix build failures
For some reason changing `.find` to `.unscoped.find` in
f766abd4cf
caused `scoping` to leak in some tests when run in isolation (looks like
a concurrency issue?). `relation_scoping_test.rb` is a case that failed.
From what I can tell it should not be possible, but changing to the
block form fixes it. There is a deeper issue that I can't seem to find.
/cc @senny
2014-11-22 15:36:50 -07:00
Sean Griffin dcc143cd70 Rename the primary key index when renaming a table in pg
Also checked to make sure this does not affect foreign key constraints.
(It doesn't).

Fixes #12856
Closes #14088
2014-11-22 13:16:14 -07:00
Sean Griffin 71bb8c34f5 ConnectionAdapter#substitute_at is technically public API...
We can't change the signature without a deprecation cycle.
2014-11-21 15:36:21 -07:00
siddharth@vinsol.com 91e3dab804 Fix includes on association with a scope containing joins along with conditions
on the joined assoiciation
2014-11-21 21:13:11 +05:30
Yves Senn f766abd4cf make it possible to access fixtures excluded by a `default_scope`.
Prior to this patch you'd end up with an error like:

```
ActiveRecord::RecordNotFound: Couldn't find <Model> with 'id'=<id> [WHERE (<default_scope condition>)]
```
2014-11-21 14:57:25 +01:00
Yves Senn dcb3ac2c3c Merge pull request #17695 from claudiob/replace-all-backticks-with-pluses
Wrap code snippets in +, not backticks, in sdoc [ci skip]
2014-11-21 11:29:41 +01:00
Sean Griffin 17efb3b919 Remove is_a? check when ignoring tables
Technically changes the API, as it will allow any object which responds
to `===`. Personally, I think this is more flexible.
2014-11-20 19:17:10 -07:00
Aaron Patterson 3e92806357 raise a better exception for renaming long indexes 2014-11-20 17:37:54 -08:00
claudiob 5aedabe82d Wrap code snippets in +, not backticks, in sdoc
I grepped the source code for code snippets wrapped in backticks in the comments
and replaced the backticks with plus signs so they are correctly displayed in
the Rails documentation.

[ci skip]
2014-11-20 15:45:15 -08:00
Sean Griffin 347c226078 Merge pull request #17669 from SamSaffron/optimise_memory
PERF: avoid string allocations
2014-11-20 08:47:34 -08:00
Yves Senn d56be864f6 synchronize code and docs for `timestamps` and `add_timestamps`.
This makes the following changes:
  * warn if `:null` is not passed to `add_timestamps`
  * `timestamps` method docs link to `add_timestamps` docs
  * explain where additional options go
  * adjust examples to include `null: false` (to prevent deprecation warnings)
2014-11-20 15:30:46 +01:00
René van den Berg 9ce105734d Explain that default_scope also influences update_all
This was not explicitly stated before and I needed to try it out to be
certain. A little explicit statement in the API docs might help here.
2014-11-20 11:56:48 +01:00
Sam a668b09ee3 PERF: avoid string allocations 2014-11-20 10:43:37 +11:00
Rafael Mendonça França 7a5a3a8828 Merge pull request #17575 from shikshachauhan/make-habtm-consistent
Allow class_name option in habtm to be consistent with other association...
2014-11-19 18:33:31 -02:00
Sean Griffin f767ac22fa Reintroduce cache with tests 2014-11-19 12:11:26 -08:00
Sean Griffin cafed35b61 Add tests for `TypeMap#fetch` and push up to `TypeMap`
It doesn't make sense for the subclass to implement this method, and not
have it on the parent. We can also DRY up the implementation of
`#lookup` to be defined in terms of fetch, which will give us a single
point of entry
2014-11-19 12:11:26 -08:00
Sean Griffin 7d54cccb84 That last test was incorrect... 2014-11-19 11:29:05 -08:00
Sean Griffin b03f9ef86a Revert "PERF: optimise type lookup to avoid invoking procs"
This reverts commit da99a2a298.
2014-11-19 11:24:49 -08:00
Sean Griffin 74c35b46e3 Introduce test to demonstrate regression caused by da99a2a2 2014-11-19 11:24:35 -08:00
Rafael Mendonça França e430019672 Merge pull request #17662 from dtaniwaki/support-symbol-foreign-key-column-to-delete
Support symbol foreign key to delete
2014-11-19 13:53:06 -02:00
dtaniwaki 995c697511 Support symbol foreign key to delete 2014-11-19 10:17:44 +09:00
Sean Griffin 08576b94ad Improve the performance of reading attributes
We added a comparison to "id", and call to `self.class.primary_key` a
*lot*. We also have performance hits from `&block` all over the place.
We skip the check in a new method, in order to avoid breaking the
behavior of `read_attribute`
2014-11-18 15:20:19 -08:00
Aaron Patterson 78e7a0d3b7 pull the preloader allocation in to a factory method 2014-11-18 14:22:33 -08:00
Sean Griffin 52fddcc653 Speed up integer casting from DB
We don't have the check the range when the value is coming from the DB,
so override type_cast_from_database to short-circuit the extra work.
The difference is huge but the absolute gain is quite small. That being
said this is a hotspot and it showed up on the radar when benchmarking
discourse.
2014-11-18 13:41:20 -08:00
Sean Griffin edc39ff756 Remove needless call to `key?` when building attributes
This appears to be a performance hotspot, see #17655.
2014-11-18 12:32:10 -08:00
Sean Griffin 3ecc5d30eb LazyAttributeHash is private 2014-11-18 12:32:09 -08:00
Sean Griffin 8b2c98f6c7 Remove call to `key?` in `LazyAttributeHash#[]`
Performance improvement, as well as improved code clarity
2014-11-18 12:32:09 -08:00
Sam 9aa2b2d7bf PERF: stop allocating the string "id" over and over 2014-11-18 21:38:27 +11:00
Godfrey Chan 3098579f27 Revert "[PERF] Speed up integer type casting from DB"
This reverts commit 6f7910a and 52c70d4.

Query params are type cased through the same method, so this approach doesn't work.
2014-11-17 18:34:29 -08:00
Godfrey Chan 52c70d496f 💅 Put escape clause first, keeps @sgrif happy 😁
See comment on 6f7910a
2014-11-17 18:09:40 -08:00
Godfrey Chan 6f7910aed5 [PERF] Speed up integer type casting from DB
We don't have the check the range when the value is coming from the DB, so
override type_cast_from_database to short-circuit the extra work.

type_cast_from_database (small)  3437507.5 (±29.2%) i/s -   14223135 in   4.996973s
type_cast_from_database (large)  3158588.7 (±28.3%) i/s -   13265628 in   4.992121s
type_cast (small)                 481984.8 (±14.2%) i/s -    2352012 in   5.005694s
type_cast (large)                 477331.8 (±14.2%) i/s -    2332824 in   5.012365s

Comparison:
type_cast_from_database (small):  3437507.5 i/s
type_cast_from_database (large):  3158588.7 i/s - 1.09x slower
type_cast (small):                 481984.8 i/s - 7.13x slower
type_cast (large):                 477331.8 i/s - 7.20x slower

The difference is huge but the absolute gain is quite small. That being said
this is a hotspot and it showed up on the radar when benchmarking discourse.
2014-11-17 17:58:49 -08:00
Sean Griffin eb26f24bde Remove the unused second argument to `substitute_at`
Oh hey, we got to remove some code because of that!
2014-11-17 15:04:40 -08:00
Sean Griffin c01b20b658 rm `reorder_bind_params`
Arel handles this for us automatically. Updated tests, as BindParam is
no longer a subclass of SqlLiteral. We should remove the second argument
to substitute_at entirely, as it's no longer used
2014-11-17 14:57:01 -08:00
Sean Griffin bf149679f4 Force table creation in tests
If something causes the teardown block to not get run (errors,
interrupting test runs), we have to manually delete them, which is a
pain.
2014-11-17 14:57:01 -08:00
Sean Griffin 29b3e548f3 Improve the performance of quoting table names on PG
This caused a pretty major performance regression for 4.2, as this is a
hotspot for query construction. We're still slightly slower than 4.1,
but it's much less significant.
2014-11-17 07:11:13 -08:00
Sean Griffin 409e7e4fc5 Remove pointless `private`
This class no longer has any private methods
2014-11-17 05:59:29 -08:00
Sam da99a2a298 PERF: optimise type lookup to avoid invoking procs 2014-11-17 14:55:17 +11:00
Sean Griffin 48f2620df9 Don't freeze the same hash we use for memoization 2014-11-14 14:30:40 -07:00
Sean Griffin 895a53e716 Allow `LazyAttributeHash` to be marshalled
`default_proc` makes a hash unmarshallable, and adds unneccessary
overhead. Since we control all access to the hash, let's just handle it
in that method. This has the side effect of improving performance on
initialization (but not neccessarily on access). We'll need to profile
further once the tests are passing.
2014-11-14 14:30:40 -07:00
Sean Griffin 3f63ac4e4d Correctly determine if an attribute is uninitialized
In real usage, we give the builder a types hash with a default value of
`Type::Value.new`. This means we need to explicitly check for the key,
rather than the truthiness of the type to determine if it's a known but
uninitialized attribute
2014-11-14 14:30:40 -07:00
Sean Griffin 0f29c21607 Reduce the amount of work performed when instantiating AR models
We don't know which attributes will or won't be used, and we don't want
to create massive bottlenecks at instantiation. Rather than doing *any*
iteration over types and values, we can lazily instantiate the object.

The lazy attribute hash should not fully implement hash, or subclass
hash at any point in the future. It is not meant to be a replacement,
but instead implement its own interface which happens to overlap.
2014-11-14 14:30:40 -07:00
Sean Griffin 70d1b5a7f8 Revert "Improve performance of AR object instantiation"
This reverts commit 8fee923888.

Conflicts:
	activerecord/lib/active_record/attribute_set/builder.rb

This solution sucks, and is hard to actually apply across the board.
Going to try other solutions
2014-11-14 14:30:39 -07:00
Sean Griffin 1c610eed94 Merge pull request #17620 from arunagw/aa-build-fix-isolated
Build fix when running in isolation
2014-11-14 08:07:42 -07:00
Sean Griffin 85b40edd94 Use `DelegateClass` instead of `SimpleDelegator` for type decorators
There is a significant performance difference between the two. Closes
2014-11-14 07:39:32 -07:00
Arun Agrawal 9ae210ba09 Build fix when running in isolation
`Computer` class needs to be require

See #17217 for more details
2014-11-14 10:24:11 +01:00
Aaron Patterson aeb917d475 exec_prepared is GVL friendly, so lets use it.
also increase the version of pg required so that people will get the
GVL friendly version
2014-11-13 15:31:54 -08:00
shiksha 07e0d8cc0c Allow habtm class_name option to be consistent with other associations 2014-11-13 11:13:44 +05:30
Andrey Deryabin b1879124a8 Follow the coding conventions 2014-11-12 15:11:36 +03:00
Yves Senn e80e16b4ff Merge pull request #17580 from ccutrer/change_table_name
add a Table#name accessor like TableDefinition#name
2014-11-11 15:29:58 +01:00
Rafael Mendonça França 1906758210 Merge pull request #17585 from aderyabin/remove_limited_update_conditions
remove never called method `limited_update_conditions`
2014-11-10 20:35:23 -02:00
Andrey Deryabin fd1364e021 remove never called method `limited_update_conditions` 2014-11-11 01:33:29 +03:00
Cody Cutrer 76e7305ea1 add a Table#name accessor like TableDefinition#name 2014-11-10 14:56:21 -07:00
Rafael Mendonça França 82e20030d4 Merge pull request #17579 from aderyabin/cleanup_sqlite
Tiny improvement in sqlite3 adapter
2014-11-10 18:01:21 -02:00
Andrey Deryabin 5e4a99821d tiny code improvement in sqlite3 adapter:
- remove unused method `supports_add_column?`
  - change additional restriction method to `valid_alter_table_type?`
  - fix code style
2014-11-10 22:55:40 +03:00
Rafael Mendonça França 7b7eea886a Merge pull request #17578 from codeodor/fix-17217-test-bug
Fix bug found when running individual tests against #17217 after merging
2014-11-10 17:44:29 -02:00
Rafael Mendonça França 2574212423 Merge pull request #11694 from Empact/association-bind-values-not-updated-on-save
Fix that a collection proxy could be cached before the save of the owner, resulting in an invalid proxy lacking the owner’s id

Conflicts:
	activerecord/CHANGELOG.md
2014-11-10 15:46:02 -02:00
Sammy Larbi c7deaa8601 Fixes a bug found when running individual tests against #17217 after merging 2014-11-10 08:33:44 -06:00
Sean Griffin 52c3a16fa0 Revert the behavior of booleans in string columns to that of 4.1
Why are people assigning booleans to string columns? >_>

We unintentionally changed the behavior on Sqlite3 and PostgreSQL.
Boolean values should cast to the database's representation of true and
false. This is 't' and 'f' by default, and "1" and "0" on Mysql. The
implementation to make the connection adapter specific behavior is hacky
at best, and should be re-visted once we decide how we actually want to
separate the concerns related to things that should change based on the
database adapter.

That said, this isn't something I'd expect to change based on my
database adapter. We're storing a string, so the way the database
represents a boolean should be irrelevant. It also seems strange for us
to give booleans special behavior at all in string columns. Why is
`to_s` not sufficient? It's inconsistent and confusing. Perhaps we
should consider deprecating in the future.

Fixes #17571
2014-11-09 20:42:36 -07:00
Sammy Larbi f43f56e16e Ensure HABTM relationships produce valid class names (Fixes #17119) 2014-11-09 11:56:07 -06:00
alfa-jpn 9bd4386850 default scopes should break the cache on singulur_association.
fixes #17495
2014-11-08 17:03:54 +09:00
Aaron Patterson c2fc9848b1 default scopes should break the cache on has_many.
if you specify a default scope on a model, it will break caching.  We
cannot predict what will happen inside the scope, so play it safe for
now.  fixes #17495
2014-11-07 16:23:15 -08:00
Yves Senn 9253417909 pg tests, get rid of `sql_types_test.rb`. 2014-11-07 10:55:45 +01:00
Yves Senn 48e3edf9ad pg tests, only execute what's necessary. 2014-11-07 10:45:34 +01:00
Yves Senn 35f502e9b6 remove the last traces of OpenBase from our codebase. [ci skip] 2014-11-07 10:12:01 +01:00
Yves Senn 58f3cf9bcb docs, the abstract data type `:timestamp` was removed. See #15184 [ci skip] 2014-11-07 10:04:40 +01:00
Yves Senn 888ea6bf44 Merge pull request #17541 from OpenSourceProjects/meaninful_message
Print out a meaningful error when ActiveRecord::ReadOnlyRecord is raised
2014-11-07 09:03:25 +01:00
Franky W d424ded6fd Print out a meaningful error when ActiveRecord::ReadOnlyRecord is raised
Currently, there is no messages which get printed out. Convoluted system
may have hooks that create other objects in which case we only fail with
no messages. This commit changes this information allowing you to know
which object is the one that actually raised the error.
2014-11-06 19:38:58 -08:00
Yves Senn 300c96ce15 tests, remove unneeded requires. 2014-11-06 15:38:03 +01:00
Yves Senn de83f28dc1 tests, use SchemaDumpingHelper to dump a specific table.
This makes debugging the generated schema output much easier.
As a side effect it also shaves off 2.5 seconds of test runtime.
2014-11-06 15:33:57 +01:00
Sean Griffin 75099a933d Remove unneccesary default parameters 2014-11-05 13:34:44 -07:00
Sean Griffin 8fee923888 Improve performance of AR object instantiation
We introduced a performance hit by adding an additional iteration
through a model's attributes on creation. We don't actually need the
values from `Result` to be a hash, we can separate the columns and
values and zip them up ourself during the iteration that we have to do.
2014-11-05 11:05:16 -07:00
Yves Senn 8e9cb9787b Merge pull request #17360 from bronzle/includes_and_unscoped
copy reflection_scopes’s unscoped value when building scope for preloading
2014-11-05 15:13:23 +01:00
Carlos Antonio da Silva 3dcd1b84dd Merge pull request #17510 from pda/ar-create-database-error-message
rake db:create shows underlying error message.
2014-11-05 08:27:09 -02:00
Yves Senn 44c7ebf5be Merge pull request #17473 from vipulnsward/rm-unused-method
Remove unused duplicated method `add_column_position` from AbstractMysqlAdapter.
2014-11-05 11:22:07 +01:00
Paul Annesley 4bcb094224 activerecord: rake db:create shows underlying error message. 2014-11-04 14:20:37 -08:00
Ted O'Meara 9007b789e1 Added SchemaDumper support for tables with jsonb columns. 2014-11-04 12:55:07 -05:00
Jason Perrin 8355b48c37 Correct test description for large integer test 2014-11-03 19:14:14 -07:00
Rafael Mendonça França faa8649dea Remove unneeded autoload 2014-11-03 16:38:50 -02:00
Rafael Mendonça França af9702c015 Merge pull request #17487 from pabloh/avoid_allocations
Avoid unnecessary allocations and method calls
2014-11-03 12:14:53 -02:00
Pablo Herrero 0488d00211 Avoid unnecessary allocations/calls 2014-11-02 21:40:47 -03:00
Andrew White badd616cc9 Add comment to point out String#[] is intentional 2014-11-02 23:58:30 +00:00
yuuji.yaginuma 1b958e0a79 Revert "Replace String index juggling with Pathname goodness in db:fixtures:load"
This reverts commit 482fdad5ef.

Fixes #17237.
2014-11-02 23:58:30 +00:00
Sean Griffin 999a07e3b9 Add an `assert_deprecated` for `sanitize_sql_hash_for_conditions` 2014-11-02 14:01:57 -07:00
Sean Griffin 76d6d88280 Handle `RangeError` from casting in `find_by` and `find_by!` on Relation
We should not behave differently just because a class has a default
scope.
2014-11-02 13:54:16 -07:00
Sean Griffin d5902c9e7e Revert deprecation of `sanitize_sql_hash_for_assignment`
This method is still used by `update_all`
2014-11-02 13:52:34 -07:00
Sean Griffin eb921000a1 Deprecate `sanitize_sql_hash_` methods on ActiveRecord
These appear to be implementation relics of times past. They duplicate
the logic in Relation, and are no longer used internally.
2014-11-02 13:34:52 -07:00
Sean Griffin d3fbd9dbb8 Pass the `SelectManager`, rather than the AST when querying w/ Relation
Arel specifically handles `SelectManager`, with the same logic we're
currently performing. The AST is `Enumerable`, which Arel looks for
separately now.
2014-11-02 12:23:44 -07:00
Sean Griffin 8b611b705b Merge pull request #17483 from pabloh/optimize_gsub_calls
Call gsub with a Regexp instead of a String for better performance
2014-11-01 18:48:23 -06:00
Sean Griffin 50e7c013c0 Don't duplicate predicate building logic in Relation finders 2014-11-01 18:16:46 -06:00
Sean Griffin 3ba9d32c6c Add a test case for range type casting
We support this behavior, but have no tests which assert that type
casting actually occurs.
2014-11-01 17:55:23 -06:00
Sean Griffin 4b53415295 Use a bound parameter for the "id = " portion of update statements
We need to re-order the bind parameters since the AST returned by the
relation will have the where statement as the first bp, which breaks on
PG.
2014-11-01 17:29:14 -06:00
Pablo Herrero 861b70e92f Call gsub with a Regexp instead of a String for better performance 2014-11-01 20:23:29 -03:00
Sean Griffin daab7e59a6 Correctly cast calculation results on PG
MySQL reports the column name as `"MAX(developer_id)"`. PG will report
it as `"max"`
2014-11-01 17:15:55 -06:00
Sean Griffin b380b1d21d [ci skip] `Relation#bind` is not public API 2014-11-01 15:58:32 -06:00
Sean Griffin 306d7a43b9 Fix test which failed in isolation
It was transitively relying on the vertex model being loaded
2014-11-01 15:49:12 -06:00
Sean Griffin 10f75af933 Use bind values for joined tables in where statements
In practical terms, this allows serialized columns and tz aware columns
to be used in wheres that go through joins, where they previously would
not behave correctly. Internally, this removes 1/3 of the cases where we
rely on Arel to perform type casting for us.

There were two non-obvious changes required for this. `update_all` on
relation was merging its bind values with arel's in the wrong order.
Additionally, through associations were assuming there would be no bind
parameters in the preloader (presumably because the where would always
be part of a join)

[Melanie Gilman & Sean Griffin]
2014-11-01 15:39:51 -06:00
Sean Griffin a431df84b5 Merge pull request #17463 from mrgilman/remove-index-from-substitute-at
Remove redundant substitute index when constructing bind values
2014-11-01 14:39:59 -06:00