Commit Graph

1273 Commits

Author SHA1 Message Date
Rafael Mendonça França
1ed92a2ee1 Merge pull request #19886 from henders/henders/reload_wipe_query_cache
Cause ActiveRecord::Base::reload to also ignore the QueryCache.
2015-05-27 23:45:55 -03:00
George Claghorn
908cfef6e2 Resolve enums in test fixtures
Currently, values for columns backing Active Record enums must be
specified as integers in test fixtures:

    awdr:
      title: "Agile Web Development with Rails"
      status: 2

    rfr:
      title: "Ruby for Rails"
      status: <%= Book.statuses[:proposed] %>

This is potentially confusing, since enum values are typically
specified as symbols or strings in application code. To resolve the
confusion, this change permits the use of symbols or strings to specify
enum values:

    awdr:
      status: :published

It is compatible with fixtures that specify enum values as integers.
2015-05-27 21:48:58 -04:00
Rafael Mendonça França
27fdf4591d Merge pull request #20269 from wojobucco/master
Changed mysqldump to include sprocs and functions
2015-05-27 22:43:23 -03:00
keepcosmos
995a473f0c add extend option on has_and_belongs_to_many. 2015-05-26 22:06:53 +09:00
Yves Senn
adfab2dcf4 deprecate Relation#uniq use Relation#distinct instead.
See #9683 for the reasons we switched to `distinct`.

Here is the discussion that triggered the actual deprecation #20198.

`uniq`, `uniq!` and `uniq_value` are still around.
They will be removed in the next minor release after Rails 5.
2015-05-26 10:35:14 +02:00
Prathamesh Sonpatki
daba090dec Pass over CHANGELOGS [ci skip] 2015-05-16 11:00:17 +05:30
Yves Senn
15354b6fd0 Merge branch 'sti-subclass-from-attributes' of https://github.com/agrobbin/rails into agrobbin-sti-subclass-from-attributes
Conflicts:
	activerecord/CHANGELOG.md
2015-05-13 11:08:10 +02:00
Alex Coomans
01f7d14494 Add full set of MySQL CLI options to support SSL authentication when using db:structure dump and load 2015-05-12 17:06:49 -07:00
Alex Robbin
cbd66b430b allow setting of a demodulized class name when using STI
If your STI class looks like this:

```ruby
class Company < ActiveRecord::Base
  self.store_full_sti_class = false

  class GoodCo < Company
  end

  class BadCo < Company
  end
end
```

The expectation (which is valid) is that the `type` in the database is saved as
`GoodCo` or `BadCo`. However, another expectation should be that setting `type`
to `GoodCo` would correctly instantiate the object as a `Company::GoodCo`. That
second expectation is what this should fix.
2015-05-11 09:02:48 -04:00
Rafael Mendonça França
02966105a5 Merge pull request #19994 from kamipo/dump_indexes_in_create_table
Dump indexes in `create_table` instead of `add_index`
2015-05-03 19:33:12 -03:00
Rafael Mendonça França
b6cc44bfa6 Merge pull request #17569 from kamipo/dump_table_options
Correctly dump `:options` on `create_table` for MySQL
2015-05-03 18:43:58 -03:00
Ryuta Kamizono
f8e748b4e8 PostgreSQL: :collation support for string and text columns
Example:

    create_table :foos do |t|
      t.string :string_en, collation: 'en_US.UTF-8'
      t.text   :text_ja,   collation: 'ja_JP.UTF-8'
    end
2015-05-04 03:53:41 +09:00
Ryuta Kamizono
99801c6a7b Dump indexes in create_table instead of add_index
If the adapter supports indexes in create table, generated SQL is
slightly more efficient.
2015-05-03 23:35:13 +09:00
Ryuta Kamizono
22ba159efc Correctly dump :options on create_table for MySQL 2015-05-03 16:41:19 +09:00
thiagoaugusto
361f1bc7c5 Improvement on Activerecord CHANGELOG 2015-05-01 11:34:19 -03:00
Yves Senn
80f011ea54 Merge pull request #19546 from DianthuDia/fix_unscope_for_less_than
Fix unscope for less than
2015-04-28 11:37:59 +02:00
Yves Senn
cdf3548a45 Merge pull request #19718 from eagletmt/find_by-without-arg
Raise ArgumentError when find_by receives no arguments
2015-04-28 11:06:53 +02:00
Yves Senn
557c46a41e Revert "Merge pull request #17920 from calebthompson/dont-rely-on-environment-task-for-schema-load"
This reverts commit 08ff4ccbbb3fb143a02e6752efb974a4bcfcd3bb, reversing
changes made to 6c9ed6dbc62450cdb87559afd15798305e069146.

Caused by #17920.

Closes #19545.

This patch introduced regressions because initializers were no longer
loaded. Specifically missing inflections result in broken restores of
the database.
2015-04-27 11:45:21 +02:00
Rafael Mendonça França
6f37d7e117 Merge pull request #18880 from mudge/timestamp-index-bug
Fix missing index when using timestamps with index
2015-04-23 13:51:55 -03:00
Yves Senn
cdbf685994 pass over CHANGELOGs. [ci skip] 2015-04-22 14:44:30 +02:00
Andrew White
ac2b7a5c4d Rename association option :class to :anonymous_class
In 1f006c an option was added called :class to allow passing anonymous
classes to association definitions. Since using :class instead of
:class_name is a fairly common typo even amongst experienced developers
this can result in hard to debug errors arising in raise_on_type_mismatch?

To fix this we're renaming the option from :class to :anonymous_class as
that is a more correct description of what the option is for. Since this
was an internal, undocumented option there is no need for a deprecation.

Fixes #19659
2015-04-21 08:48:22 -04:00
Sean Griffin
d849f42b4e Autosave existing records on HMT associations when the parent is new
To me it seems like this should only be the case if `autosave: true` is
set on the association. However, when implemented that way, it caused
issues with has many associations, where we have explicit tests stating
that child records are updated when the parent is new, even if autosave
is not set (presumably to update the parent id, but other changed
attributes would be persisted as well).

It's quirky, but at least we should be consistently quirky. This
constitutes a minor but subtle change in behavior, and therefore should
not be backported to 4.2 and earlier.

Fixes #19782
2015-04-18 10:47:04 -04:00
Paul Mucur
c0abeadc0e Fix missing index when using timestamps with index
The `index` option used with `timestamps` should be passed to both
`column` definitions for `created_at` and `updated_at` rather than just
the first.

This was happening because `Hash#delete` is used to extract the `index`
option passed to `timestamps`, thereby mutating the `options` hash
in-place. Now take a copy of the `options` before deleting so that the
original is not modified.
2015-04-15 09:53:55 +01:00
Yves Senn
5f00ed10dd Revert "Merge pull request #19755 from yuki24/activerecord/support-for-set"
This reverts commit 524d40591eaa2f4d007409bfad386f6b107492eb, reversing
changes made to 34d3a6095100245283861ef480a54d0643bbee4c.

Reasoning behind the revert are in the PR discussion:
https://github.com/rails/rails/pull/19755

- This means that types can no longer cast to/from `Set`, and reasonably
  work with `where` (we already have this problem for `array`/`json`
  types on pg)
- This adds precedent for every other `Enumerable`, and we can't target
  `Enumerable` directly.
- Calling `to_a` on a `Set` is reasonable.
2015-04-15 09:10:00 +02:00
Yves Senn
524d40591e Merge pull request #19755 from yuki24/activerecord/support-for-set
Add support for Set to Relation#where
2015-04-14 08:57:10 +02:00
Yuki Nishijima
50cae600bd Add support for Set to Relation#where
Previously `#where` used to treat `Set`objects as nil, but now it treats
them as an array:

  set = Set.new([1, 2])
  Author.where(:id => set)
  # => SELECT "authors".* FROM "authors" WHERE "authors"."id" IN (1, 2)
2015-04-13 20:13:37 -07:00
Sean Griffin
67c2deeb4b Merge branch 'fix_uniqueness_validation_when_value_is_out_of_range' 2015-04-08 11:07:39 -06:00
Andrey Voronkov
1a36be390e Fix uniqueness validation with out of range value 2015-04-08 19:28:45 +03:00
Jeremy Kemper
bd51bbc028 Merge pull request #17574 from kamipo/charset_collation_options
Add charset and collation options support for MySQL string and text columns.
2015-04-07 09:40:16 -07:00
Yves Senn
51eacc71c7 Merge pull request #19652 from vngrs/pluralize_foreign_key_table_name_bug
use singular table name if pluralize_table_names is setted as false whil...
2015-04-06 10:42:44 +02:00
Sean Griffin
445c12f7df Reduce memory usage when loading types in PG
We were never clearing the `PG::Result` object used to query the types
when the connection is first established. This would lead to a
potentially large amount of memory being retained for the life of the
connection.

Investigating this issue also revealed several low hanging fruit on the
performance of these methods, and the number of allocations has been
reduced by ~90%.

Fixes #19578
2015-03-29 13:54:39 -06:00
Jason Nochlin
4d6fbe2934 Add config.active_record.warn_on_records_fetched_greater_than option
When set to an integer, a warning will be logged whenever a result set
larger than the specified size is returned by a query. Fixes #16463

The warning is outputed a module which is prepended in an initializer,
so there will be no performance impact if
`config.active_record.warn_on_records_fetched_greater_than` is not set.
2015-03-25 16:50:11 -04:00
Yves Senn
30a5cd9c8b Merge pull request #19503 from jasoncodes/no-psqlrc
Avoid loading user's psqlrc when loading test structure
2015-03-25 09:42:45 +01:00
Carlos Antonio da Silva
bfd5bf8313 Merge pull request #19452 from pinglamb/fix-referencing-wrong-alias-when-joining-tables-of-has-many-through-association
Fix referencing wrong aliases while joining tables of has many through association
2015-03-24 08:00:59 -03:00
Matthew Draper
8b96c0b7a3 Make sure to persist a newly-nil serialized value
The subtype will (quite reasonably) ignore the possibility that it has
`changed_in_place?` by becoming nil.

Fixes #19467
2015-03-23 15:27:03 +10:30
Carlos Antonio da Silva
8a45e18f11 Move #19447 changelog to the top and reword it a bit [ci skip] 2015-03-22 19:11:06 -03:00
pinglamb
ba057a5ebb Fix referencing wrong aliases while joining tables of has many through
association

While joining table of has_many :through association, ActiveRecord will
use the actual table name instead of through-join alias. It results with
a wrong SQL and exception is raised. This only happens when calculation
methods like #count is called.

This issue is affecting Rails 4.1.x and 4.2.x as well.
2015-03-22 16:25:23 +08:00
wallerjake
9bc4eb7ee1 Delegate limit to subtype
As described here https://github.com/rails/rails/issues/19420. When
using the Postgres BigInt[] field type the big int value was not being
translated into schema.rb. This caused the field to become just a
regular integer field when building off of schema.rb. This fix will
address this by delegating the limit from the subtype to the Array type.

https://github.com/rails/rails/issues/19420
2015-03-21 19:32:41 -05:00
Yves Senn
dfdb08f092 Merge pull request #19406 from larskanis/add_changelog_entry_for_17680
ActiveRecord: Add a changelog entry for issue #17680. [ci skip]
Conflicts:
	activerecord/CHANGELOG.md
2015-03-19 14:06:26 +01:00
Jon Atack
dbf5433978 Active Record changelog pass [skip ci] 2015-03-19 10:04:11 +05:30
Yves Senn
08615a3bcb Merge pull request #19348 from Empact/null-scope
Reuse the CollectionAssociation#reader proxy cache if the foreign key is present from the start.

Conflicts:
	activerecord/CHANGELOG.md
2015-03-18 11:20:47 +01:00
Ryan Wallace
7ab36f4532 Add config.active_record.dump_schemas.
Fixes db:structure:dump when using schema_search_path and PostgreSQL
extensions.

Closes #17157.
2015-03-17 10:43:26 -07:00
Brandon Weiss
0965863564 Closes rails/rails#18864: Renaming transactional fixtures to transactional tests
I’m renaming all instances of `use_transcational_fixtures` to
`use_transactional_tests` and “transactional fixtures” to
“transactional tests”.

I’m deprecating `use_transactional_fixtures=`. So anyone who is
explicitly setting this will get a warning telling them to use
`use_transactional_tests=` instead.

I’m maintaining backwards compatibility—both forms will work.
`use_transactional_tests` will check to see if
`use_transactional_fixtures` is set and use that, otherwise it will use
itself. But because `use_transactional_tests` is a class attribute
(created with `class_attribute`) this requires a little bit of hoop
jumping. The writer method that `class_attribute` generates defines a
new reader method that return the value being set. Which means we can’t
set the default of `true` using `use_transactional_tests=` as was done
previously because that won’t take into account anyone using
`use_transactional_fixtures`. Instead I defined the reader method
manually and it checks `use_transactional_fixtures`. If it was set then
it should be used, otherwise it should return the default, which is
`true`. If someone uses `use_transactional_tests=` then it will
overwrite the backwards-compatible method with whatever they set.
2015-03-16 11:35:44 -07:00
Ben Woosley
c82cc222c7 Reuse the CollectionAssociation#reader proxy cache if the foreign key is present from the start.
When a new record has the necessary information prior to save, we can
avoid busting the cache.

We could simply clear the @proxy on #reset or #reset_scope, but that
would clear the cache more often than necessary.
2015-03-15 17:29:05 -07:00
Matt Brictson
ba7532700f Require pg~>0.18 to ensure Ruby 2.2 compatibility
Versions of the pg gem earlier than 0.18.0 cannot be used safely with Ruby 2.2.
Specifically, pg 0.17 when used with Ruby 2.2 has a known bug that causes
random bits to be added to the end of strings. Further explanation here:
https://bitbucket.org/ged/ruby-pg/issue/210/crazy-bytes-being-added-to-record
2015-03-11 22:23:36 -07:00
Ryuta Kamizono
0aa83f3b88 Add :charset and :collation options support for MySQL string and text columns
Example:

    create_table :foos do |t|
      t.string :string_utf8_bin, charset: 'utf8', collation: 'utf8_bin'
      t.text   :text_ascii,      charset: 'ascii'
    end
2015-03-06 18:56:19 +09:00
Ryuta Kamizono
6fa6c739d1 Correctly dump serial and bigserial 2015-03-04 17:52:11 +09:00
Yves Senn
1b356c2e7a add CHANGELOG entry for #19176. [ci skip] 2015-03-04 08:46:12 +01:00
Arthur Neves
4e757746a6 Add changelog for #15549 fix [skip ci] 2015-02-27 16:05:28 -05:00
Sean Griffin
38218929e9 Properly create through records when called with where
Various behaviors needed by associations (such as creating the through
record) are lost when `where` is called, since we stop having a
`CollectionProxy` and start having an `AssociationRelation` which does
not contain this behavior. I *think* we should be able to rm
`AssociationRelation`, but we have tests saying the changes required to
do that would be bad (Without saying why. Of course. >_>)

Fixes #19073.
2015-02-26 12:42:55 -07:00
Ryuta Kamizono
3239b6a98a Add SchemaMigration.create_table support any unicode charsets for MySQL.
MySQL unicode support is not only `utf8mb4`.
Then, The index length problem is not only `utf8mb4`.

http://dev.mysql.com/doc/refman/5.6/en/charset-unicode.html

    SELECT * FROM information_schema.character_sets WHERE maxlen > 3;
    +--------------------+----------------------+------------------+--------+
    | CHARACTER_SET_NAME | DEFAULT_COLLATE_NAME | DESCRIPTION      | MAXLEN |
    +--------------------+----------------------+------------------+--------+
    | utf8mb4            | utf8mb4_general_ci   | UTF-8 Unicode    |      4 |
    | utf16              | utf16_general_ci     | UTF-16 Unicode   |      4 |
    | utf16le            | utf16le_general_ci   | UTF-16LE Unicode |      4 |
    | utf32              | utf32_general_ci     | UTF-32 Unicode   |      4 |
    +--------------------+----------------------+------------------+--------+
2015-02-26 07:57:53 +09:00
Yves Senn
72c1557254 rework disable_referential_integrity for PostgreSQL.
[Toby Ovod-Everett & Andrey Nering & Yves Senn]

Closes #17726.
Closes #10939.

This patch makes three distinct modifications:

1. no longer fall back to disabling user triggers if system triggers can't be disabled
2. warn the user when referential integrity can't be disabled
3. restore aborted transactions when referential integrity can't be disabled

The motivation behind these changes is to make the behavior of Rails
transparent and less error-prone. To require superuser privileges is not optimal
but it's what Rails currently needs. Users who absolutely rely on disabling user triggers
can patch `disable_referential_integrity`.

We should investigate `SET CONSTRAINTS` as a possible solution which does not require
superuser privileges.

/cc @matthewd
2015-02-24 17:32:35 +01:00
Ryuta Kamizono
b8d320c129 Allow :limit option for MySQL bigint primary key support
Example:

    create_table :foos, id: :primary_key, limit: 8 do |t|
    end

    # or

    create_table :foos, id: false do |t|
      t.column :id, limit: 8
    end
2015-02-24 01:53:54 +09:00
Yves Senn
e71f5dad4e some indenting and punctuation fixes. [ci skip] 2015-02-23 16:54:40 +01:00
Josef Šimánek
6576f7354e Require belongs_to by default.
Deprecate `required` option in favor of `optional` for belongs_to.
2015-02-21 23:03:10 +01:00
Rafael Mendonça França
0f2261f2d1 Merge pull request #17139 from mfazekas/fix_becomes_changed_attributes
Always reset changed attributes in becomes
2015-02-20 15:01:28 -02:00
Ryuta Kamizono
a088ee9691 Format the time string according to the precision of the time column
It is also necessary to format a time column like a datetime column.
2015-02-20 10:25:31 +09:00
Ryuta Kamizono
9ef870c042 Allow :precision option for time type columns 2015-02-20 10:24:08 +09:00
Rafael Mendonça França
e28721baf2 Copy edit the suppressor documentation
[ci skip]
2015-02-19 09:08:51 -02:00
Michael Ryan
b9a1e9a4b2 Add ActiveRecord::Base.suppress 2015-02-18 18:30:05 -05:00
Hyonjee Joo
219d71fb90 Add time option to #touch
Fixes #18905. `#touch` now takes time as an option. Setting the option
saves the record with the updated_at/on attributes set to the current time
or the time specified. Updated tests and documentation accordingly.
2015-02-18 10:22:13 -05:00
Sean Griffin
89ba5bb456 Revert "Allow :precision option for time type columns"
This reverts commit 1502caefd30b137fd1a0865be34c5bbf85ba64c1.

The test suite for the mysql adapter broke when this commit was used
with MySQL 5.6.

Conflicts:
	activerecord/CHANGELOG.md
2015-02-17 11:12:52 -07:00
Vipul A M
6598272770 Deprecated passing of start value to find_in_batches and find_each in favour of begin_at value. 2015-02-17 14:10:35 +05:30
Yves Senn
6bd777c851 Merge pull request #18662 from estum/foreign-key-exists
Add `foreign_key_exists?` method.
2015-02-16 09:39:59 +01:00
Yves Senn
57a1d2bf9d remove CHANGELOG entry for Rails 5.0 only feature. #18918
`has_secure_token` hasen't been released yet. No need to track
every change in the CHANGELOG.
2015-02-13 09:16:22 +01:00
Wojciech Wnętrzak
0817bb06f7 Do not overwrite secret token value when already present.
```
user = User.create(token: "custom-secure-token")
user.token # => "custom-secure-token"
```
2015-02-12 22:05:45 +01:00
Eugene Gilburg
d7a7a050e1 Optimize none? and one? relation query methods to use LIMIT and COUNT.
Use SQL COUNT and LIMIT 1 queries for none? and one? methods if no block or limit is given,
instead of loading the entire collection to memory. The any? and many? methods already
follow this behavior.

[Eugene Gilburg & Rafael Mendonça França]
2015-02-12 17:40:59 -02:00
Ryuta Kamizono
1502caefd3 Allow :precision option for time type columns 2015-02-12 07:23:53 +09:00
Sean Griffin
c51f9b61ce Refactor enum to be defined in terms of the attributes API
In addition to cleaning up the implementation, this allows type casting
behavior to be applied consistently everywhere. (#where for example). A
good example of this was the previous need for handling value to key
conversion in the setter, because the number had to be passed to `where`
directly. This is no longer required, since we can just pass the string
along to where. (It's left around for backwards compat)

Fixes #18387
2015-02-11 15:02:36 -07:00
Sean Griffin
5e0b555b45 current_scope shouldn't pollute sibling STI classes
It looks like the only reason `current_scope` was thread local on
`base_class` instead of `self` is to ensure that when we call a named
scope created with a proc on the parent class, it correctly uses the
default scope of the subclass. The reason this wasn't happening was
because the proc captured `self` as the parent class, and we're not
actually defining a real method. Using `instance_exec` fixes the
problem.

Fixes #18806
2015-02-11 13:46:30 -07:00
Yves Senn
a893718c31 fix remove_reference with foreign_key: true on MySQL. #18664.
MySQL rejects to remove an index which is used in a foreign key constraint:

```
ActiveRecord::StatementInvalid: Mysql2::Error: Cannot drop index 'index_copies_on_title_id': needed in a foreign key constraint: ALTER TABLE `copies` DROP `title_id`
```

Removing the constraint before removing the column (and the index) solves this problem.
2015-02-11 11:20:59 +01:00
Rafael Mendonça França
3d91083e14 Merge pull request #18877 from prathamesh-sonpatki/ar-changelog-typos-2
Fixed typos in ActiveRecord CHANGELOG [ci skip]
2015-02-10 17:23:13 -02:00
Prathamesh Sonpatki
cb7190aa9c Fixed typos in ActiveRecord CHANGELOG [ci skip] 2015-02-11 00:43:51 +05:30
Vipul A M
3dc432068b Add an option end_at to find_in_batches
that complements the `start`parameter to specify where to stop batch processing
2015-02-09 01:33:57 +05:30
Ryuta Kamizono
f983912037 Fix rounding problem for PostgreSQL timestamp column
If timestamp column have the precision, it need to format according to
the precision of timestamp column.
2015-02-08 22:22:55 +09:00
Ryuta Kamizono
0bbff5ee16 Respect the database default charset for schema_migrations table.
The charset of `version` column in `schema_migrations` table is depend
on the database default charset and collation rather than the encoding
of the connection.
2015-02-08 11:19:33 +09:00
Rafael Mendonça França
b71e08f8ba Raise ArgumentError when passing nil to Relation#merge
nil or false should not be valid argument to the merge method.

Closes #12264
2015-02-06 17:53:06 -02:00
Rafael Mendonça França
25bbe595f1 Merge pull request #18399 from kommen/unify-structure-file-envvar-names
Use SCHEMA instead of DB_STRUCTURE for specifiying structure file.

Conflicts:
	activerecord/CHANGELOG.md
2015-02-05 18:55:33 -02:00
Sean Griffin
cd0ed12d1a Respect custom primary keys for associations in Relation#where
While we query the proper columns, we go through normal handling for
converting the value to a primitive which assumes it should use the
table's primary key. If the association specifies a different value (and
we know that we're working with an association), we should use the
custom primary key instead.

Fixes #18813.
2015-02-04 08:56:46 -07:00
Miklos Fazekas
5f6370a81b Always reset changed attributes in becomes
When ```becomes``` changes @attributes it should also change
@changed_attributes. Otherwise we'll experience a kind of split head situation
where attributes are coming from ```self```, but changed_attributes is coming
from ```klass.new```. This affects the inheritance_colmn as it's changed by new
for example.

Fixes #16881
2015-02-04 15:42:14 +01:00
Sean Griffin
23bb8d77c6 Correct errors in counter cache updating
The cache name should be converted to a string when given, not compared
as a symbol. This edge case is already adequately covered by our tests,
but was masked by another issue where we were incorrectly updating the
counter cache twice. When paired with a bug where we didn't update the
counter cache because we couldn't find a match with the name, this made
it look like everything was working fine.

Fixes #10865.
2015-02-03 13:28:07 -07:00
Chris Sinjakli
b8e1f20267 Generate consistent names for foreign keys 2015-02-03 01:37:29 +00:00
eileencodes
27aa4dda7d Fix validations on child record when record parent has validate: false
Fixes #17621. This 5 year old (or older) issue causes validations to fire
when a parent record has `validate: false` option and a child record is
saved. It's not the responsibility of the model to validate an
associated object unless the object was created or modified by the
parent.

Clean up tests related to validations

`assert_nothing_raised` is not benefiting us in these tests
Corrected spelling of "respects"
It's better to use `assert_not_operator` over `assert !r.valid`
2015-02-01 16:03:49 -08:00
Aaron Patterson
aa8ade5811 Merge branch 'master' into mdluo-master
* master:
  Move required error message and changelog to Active Record
  Use public Module#include, in favor of https://bugs.ruby-lang.org/issues/8846
  Use Module#include instead of send :include, since now is a public method [ci skip]
  ✂️ warning from controller renderer test

Conflicts:
	activerecord/CHANGELOG.md
2015-02-01 08:42:22 -08:00
Carlos Antonio da Silva
fdeef19833 Move required error message and changelog to Active Record
The new association error belongs to Active Record, not Active Model.
See #18700 for reference.
2015-02-01 10:31:54 -02:00
Mingdong Luo
549d171a90 Merge branch 'master' into pr/18316
Conflicts:
	activerecord/CHANGELOG.md
2015-01-31 19:23:48 -08:00
Yves Senn
afe402dac7 unify CHANGELOG format. [ci skip] 2015-01-31 11:54:00 +01:00
Bogdan Gusiev
e94330fe40 Fixed AR::Relation#group method when argument is a SQL reserved keyword 2015-01-29 17:27:02 +02:00
Matthew Draper
b0b37942d7 Added #or to ActiveRecord::Relation
Post.where('id = 1').or(Post.where('id = 2'))
    # => SELECT * FROM posts WHERE (id = 1) OR (id = 2)

[Matthew Draper & Gael Muller]
2015-01-28 13:35:55 -07:00
Sean Griffin
56a3d5ec91 Don't redefine autosave association callbacks in nested attrs
These callbacks will already have been defined when the association was
built. The check against `reflection.autosave` happens at call time, not
at define time, so simply modifying the reflection is sufficient.

Fixes #18704
2015-01-28 09:53:38 -07:00
Sean Griffin
7c6f3938de Move integer range validation to never raise on assignment
Given that this was originally added to normalize an error that would
have otherwise come from the database (inconsistently), it's more
natural for us to raise in `type_cast_for_database`, rather than
`type_cast_from_user`. This way, things like numericality validators can
handle it instead if the user chooses to do so. It also fixes an issue
where assigning an out of range value would make it impossible to assign
a new value later.

This fixes several vague issues, none of which were ever directly
reported, so I have no issue number to give. Places it was mentioned
which I can remember:

- 9ba21381d7/lib/shoulda/matchers/active_model/allow_value_matcher.rb (L261-L263)
- https://github.com/rails/rails/issues/18653#issuecomment-71197026
2015-01-23 14:30:23 -07:00
Sean Griffin
96e504ec8a Errors raised in type_cast_for_database no longer raise on assignment
Fixes #18580.
2015-01-23 12:50:01 -07:00
Sean Griffin
b9d668f8cb Don't remove join dependencies in Relation#exists?
Fixes #18632
2015-01-23 12:05:14 -07:00
Sean Griffin
e8460f8bbe Don't error when invalid json is assigned to a JSON column
Keeping with our behavior elsewhere in the system, invalid input is
assumed to be `nil`.

Fixes #18629.
2015-01-21 11:48:32 -07:00
Sean Griffin
be9b68038e Introduce ActiveRecord::Base#accessed_fields
This method can be used to see all of the fields on a model which have
been read. This can be useful during development mode to quickly find
out which fields need to be selected. For performance critical pages, if
you are not using all of the fields of a database, an easy performance
win is only selecting the fields which you need. By calling this method
at the end of a controller action, it's easy to determine which fields
need to be selected.

While writing this, I also noticed a place for an easy performance win
internally which I had been wanting to introduce. You cannot mutate a
field which you have not read. Therefore, we can skip the calculation of
in place changes if we have never read from the field. This can
significantly speed up methods like `#changed?` if any of the fields
have an expensive mutable type (like `serialize`)

```
Calculating -------------------------------------
 #changed? with serialized column (before)
                       391.000  i/100ms
 #changed? with serialized column (after)
                         1.514k i/100ms
-------------------------------------------------
 #changed? with serialized column (before)
                          4.243k (± 3.7%) i/s -     21.505k
 #changed? with serialized column (after)
                         16.789k (± 3.2%) i/s -     84.784k
```
2015-01-20 14:42:15 -07:00
Jeremy Kemper
b477ad54e5 Merge pull request #18458 from brainopia/fix_after_commit_for_fixtures
Support after_commit callbacks in transactional fixtures
2015-01-20 09:53:15 -07:00
Yves Senn
6b2be718f6 Merge pull request #18597 from kamipo/add-if-exists-to-drop-table
Add an `:if_exists` option to `drop_table`
2015-01-20 13:14:24 +01:00
Stefan Kanev
48e99a4531 Add an :if_exists option to drop_table
If set to `if_exists: true`, it generates a statement like:

    DROP TABLE IF EXISTS posts

This syntax is supported in the popular SQL servers, that is (at least)
SQLite, PostgreSQL, MySQL, Oracle and MS SQL Sever.

Closes #16366.
2015-01-19 13:40:13 +09:00
Prathamesh Sonpatki
3faa223541 Fix wording in AR CHANGELOG about time columns change [ci skip] 2015-01-19 08:57:22 +05:30
Prathamesh Sonpatki
0fcd4cf5c2 Run SQL only if attribute changed for update_attribute method
- This is based on https://github.com/rails/rails/issues/18400 but
   tackling same issue with update_attribute method instead of update method.
2015-01-18 20:00:57 +05:30